On Thu, 2008-12-04 at 04:58 -0800, Karantir wrote:
> Hi,
> 
> I've just found strange django behaviour and want to understand is it
> a bug or an inconvenient feature. I have two models -- Place and Item
> bound through the intermediate table ItemPlace (that stores additional
> field -- quantity). Physically it describes some quantity of items
> lying on the some places.
> 
> Then i've tried to fetch spare places with the following request:
> Place.objects.filter(itemplace__quantity = None) and it works
> perfectly. After that i've run Place.objects.exclude
> (itemplace__quantity = None) to fetch occupied places but this request
> anyway returns an empty list.
> 
> Surely i can use Place.objects.filter(itemplace__quantity__gte = 0)
> and it works but why the previous request fails? Any ideas?

The answer to your question is going to depend on specifics of your
models (which you haven't supplied).

However, the exclude() and the second filter() are asking for different
things. The exclude() will remove any Places that have a NULL itemplace
value or a NULL itemplace.quantity value. The second filter() will
include anything where itemplace.quantity has a positive value. Since 0
is not the same as NULL, the two queries will treat zero values
differently (although I would have expected the first exclude to return
a superset of the second filter).

There is one class of known bugs with exclude() and many-to-many that
you may or may not be hitting here. I've been spending quite a lot of
time fixing (working on fixing, at least) those lately. You might be
getting bitten by that or you might not. If you could post a very short
sample model that demonstrates the problem you are seeing, it would
help.

Regards,
Malcolm

> > 
> 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to