On Wed, 2008-04-23 at 06:03 -0700, bobhaugen wrote:
> Replying to myself with more clues:
>
> I see the problem:
>
> For this filter statement:
> items = InventoryItem.objects.filter(
> Q(inventory_date__range=(weekstart, thisdate), received__exact=0)
> |
> Q(onhand__gt=0))
>
> ,,, the SQL generated looks like this:
> SELECT
> "orders_inventoryitem"."id","orders_inventoryitem"."producer_id","orders_inventoryitem"."product_id","orders_inventoryitem"."inventory_date","orders_inventoryitem"."planned","orders_inventoryitem"."received","orders_inventoryitem"."onhand"
> FROM "orders_inventoryitem" WHERE
> (("orders_inventoryitem"."inventory_date" BETWEEN 2008-04-21 AND
> 2008-04-23 OR "orders_inventoryitem"."received" = 0.00 OR
> "orders_inventoryitem"."onhand" > 0.00)) ORDER BY
> "orders_inventoryitem"."product_id" ASC,
> "orders_inventoryitem"."producer_id" ASC,
> "orders_inventoryitem"."inventory_date" ASC'}
>
> So the SQL ORs all of the Q clauses, and does not separate the Q
> clause that I thought should have been ANDed.
Complex Q-object combinations on trunk do have a few problems (bugs). It
turns out to be quite hard to get all the combinations working
correctly. This is one of the areas that development of the
queryset-refactor branch has devoted a lot of time to fixing, so things
will improve in trunk very soon (or you can try out your code on the
branch).
Without spending too much time on it, though, it looks like your
intuition about how Q-objects should work is pretty much correct and the
SQL construction is just not behaving itself.
Regards,
Malcolm
--
Borrow from a pessimist - they don't expect it back.
http://www.pointy-stick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---