Re: .filter() and .exclude() don't add up

2013-07-31 Thread akaariai
On Tuesday, July 30, 2013 6:26:47 PM UTC+3, Daniele Procida wrote: > > On Mon, Jul 29, 2013, akaariai wrote: > > >> I understood that part. But by "more general" I mean one that will work > >> for any case, without having to know where the Nulls might be. > >> > >> So

Re: .filter() and .exclude() don't add up

2013-07-30 Thread Daniele Procida
On Mon, Jul 29, 2013, akaariai wrote: >> I understood that part. But by "more general" I mean one that will work >> for any case, without having to know where the Nulls might be. >> >> So given queryset A, and its subset queryset B, we can place B against A >> and obtain

Re: .filter() and .exclude() don't add up

2013-07-29 Thread akaariai
On Sunday, July 28, 2013 10:44:49 AM UTC+3, Daniele Procida wrote: > > On Sat, Jul 27, 2013, Steve McConville > wrote: > > >Perhaps I'm not sure exactly what you mean by "more general", but I > >was recommending something like > > > >red_things =

Re: .filter() and .exclude() don't add up

2013-07-28 Thread Daniele Procida
On Sat, Jul 27, 2013, Steve McConville wrote: >Perhaps I'm not sure exactly what you mean by "more general", but I >was recommending something like > >red_things = queryset.filter(Q(color="red")) >non_red_things = queryset.filter(~Q(color="red") |

Re: .filter() and .exclude() don't add up

2013-07-27 Thread Steve McConville
Perhaps I'm not sure exactly what you mean by "more general", but I was recommending something like red_things = queryset.filter(Q(color="red")) non_red_things = queryset.filter(~Q(color="red") | Q(color__isnull=True) This will produce SQL like SELECT * FROM queryset WHERE color IS 'red';

Re: .filter() and .exclude() don't add up

2013-07-27 Thread Daniele Procida
On Fri, Jul 26, 2013, Steve McConville 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 -

Re: .filter() and .exclude() don't add up

2013-07-27 Thread Daniele Procida
On Fri, Jul 26, 2013, Bill Freeman wrote: >You really should figure out which record isn't showing up in either sub >case and look at it in detail to see if NULLs are involved before you spend >time trying to fix a problem that you don't have. > >You could, for example collect

Re: .filter() and .exclude() don't add up

2013-07-26 Thread Steve McConville
> 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

Re: .filter() and .exclude() don't add up

2013-07-26 Thread Bill Freeman
You really should figure out which record isn't showing up in either sub case and look at it in detail to see if NULLs are involved before you spend time trying to fix a problem that you don't have. You could, for example collect all the ids from the several queries into python sets, union the

Re: .filter() and .exclude() don't add up

2013-07-26 Thread Daniele Procida
On Fri, Jul 26, 2013, Steve McConville wrote: >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). Good point, I will

Re: .filter() and .exclude() don't add up

2013-07-26 Thread Steve McConville
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

.filter() and .exclude() don't add up

2013-07-26 Thread Daniele Procida
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