Re: .filter() and .exclude() don't add up
Firstly (and I don't think this is the cause of the problem) you're
calling datetime.now() four times, which will give you four different
datetimes (ie. the queries will not be completely identical). Secondly
SQL uses a 3-valued logic (with null) so if any of the fields you're
filtering on are nullable you may not be able to rely on the law of
the excluded middle:
https://en.wikipedia.org/wiki/Null_(SQL)#Law_of_the_excluded_fourth_.28in_WHERE_clauses.29
On 26 July 2013 16:57, Daniele Procida <daniele@vurt.org> wrote:
> How is this possible?
>
> # we start with a queryset actual_events
>
> # get forthcoming_events using filter()
>
> forthcoming_events = actual_events.filter(
> Q(single_day_event = True, date__gte = datetime.now()) | \
> Q(single_day_event = False, end_date__gte = datetime.now())
> )
>
> # get previous_events using exclude() and exactly the same terms as above
>
> previous_events = actual_events.exclude(
> Q(single_day_event = True, date__gte = datetime.now()) | \
> Q(single_day_event = False, end_date__gte = datetime.now())
> )
>
> # And now:
>
> # actual_events.count(): 467
> # forthcoming_events.count(): 24
> # previous_events.count(): 442
>
> SInce I have run .filter() and .exclude() with identical terms, should they not between them contain all the items in the queryset they acted upon, *whatever* the terms used?
>
> 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+unsubscribe@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.
>
>
--
steve
http://stevemcconville.com/
--
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+unsubscribe@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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home