On Fri, Jul 26, 2013, Steve McConville <mcconville.st...@gmail.com> wrote:

>> So, if one of the fields can be Null, then *neither*:
>>
>>     queryset.filter(field=value)
>>
>>     queryset.exclude(field=value)
>>
>> will match a record where it's Null?
>
>As I understand it, this is correct - it's certainly the way SQL was designed.
>
>> In that case, is there a better - more reliable - way than using
>both .filter() and .exclude() with the same terms to split a queryset
>into all those items that match a filter, and all those that don't?
>
>As well as doing the queries above, you can get the nulls by doing
>
>queryset.filter(field__isnull=True)

I meant is there a more general way of doing something like:

    red_things = queryset.filter(colour="red") # get red things

    non_red_things = queryset - red_things # get all other things

Maybe this simply isn't possible in SQL.

Daniele

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to