Feature Request: delete_selected explicit option in admin

2012-01-30 Thread sbrandt
Hi,

according to this 
topic
 the 
only way to let the admin call delete() on every model using the 
delete_selected admin action is to copy the function, delete the 
queryset.delete()-method, add a obj.delete() in the loop, change the 
template path, copy the template and change the action name in it.
In addition, actions=[my_own_delete_selected] in the ModelAdmin class 
doesn't do the job, you must overwrite the get_actions method. That's much 
effort for such a simple task, especially because overwriting the delete() 
method is common as far as I know.

We could introduce a new admin option, let's say 
"ModelAdmin.delete_explicit" to do the job:

in django/contrib/actions/admin.py:45 (Django 1.3)
for obj in queryset:
obj_display = force_unicode(obj)
modeladmin.log_deletion(request, obj, obj_display)
queryset.delete()

for obj in queryset:
obj_display = force_unicode(obj)
modeladmin.log_deletion(request, obj, obj_display)
if modeladmin.delete_explicit:
obj.delete()
if not modeladmin.delete_explicit:
queryset.delete() 

Letting delete_explicit default to false, the change would be backwards 
compatible. 
Just a draft... What do you uthink?

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/BVaJdKtfF3gJ.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.



Re: Query on BooleanField with values other than True and False, bug or intentional?

2016-01-22 Thread sbrandt
I agree on the "it is the job of the user" thing as well as on the 
predictability on IntegerField, but there is at least one case where this 
goes horribly wrong. Imagine in the web-world we are receiving JSON and for 
some case, the browser sends "false" as a string. `bool('false') -> True`.

One could say this is again a mistake of the app developer, but my 
understanding of "explicit is better than implicit" is that Django should 
explicitly protect me from those mistakes that could stay undetected for a 
*very* long time because it just happily silently implicitly converts data 
types like PHP.

Maybe a backwards compatible solution here would be to provide an 
`strict=False` parameter to model fields or provide `StrictIntegerField` 
etc subclasses, although this may end up in a mess.

Am Freitag, 22. Januar 2016 22:18:45 UTC+1 schrieb Maxime Lorant:
>
> At least, the behaviour is predictable : it uses `bool(value)`. I believe 
> it is not a bug but more a question about the input definition: should we 
> allow non boolean value? I don't see any problem here accepting a string as 
> a `True` value, it is the job of the user to ensure the value is castable 
> to a boolean.
>
> The same behaviour is found on `IntegerField` for example: 
> `Model.objects.filter(pk="foo")` raises `ValueError: invalid literal for 
> int() with base 10: 'foo'` which implies the ORM tried to cast 'foo' as an 
> integer.
>
> On Friday, January 22, 2016 at 8:51:41 PM UTC+1, Kaveh wrote:
>>
>> Today I discovered I can use strings and numbers to query on 
>> BooleanFields.
>>
>> Let's say we have the following model:
>>
>> class Whatever(models.Model):
>> name = models.CharField(max_length=200)
>> is_active = models.BooleanField()
>>
>> The following queries return all instances which their `is_active` field 
>> is True:
>>
>> Whatever.object.filter(is_active=True)
>> Whatever.object.filter(is_active='some_random_text')
>> Whatever.object.filter(is_active=777)
>>
>> and the followings return the ones which are False:
>>
>> Whatever.object.filter(is_active=False)
>> Whatever.object.filter(is_active='')
>> Whatever.object.filter(is_active=0)
>>
>> Is this behaviour intentional or is it a bug? Should queries on 
>> BooleanFields accept strings and numbers?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/8d9458df-72ca-4e70-9d22-110c8473d61d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.