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.
On the other hand, this single Q query properly generates ANDed
clauses:
items = InventoryItem.objects.filter(
Q(inventory_date__range=(weekstart, thisdate),
received__exact=0))
The SQL:
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 AND "orders_inventoryitem"."received" = 0.00) ORDER BY
"orders_inventoryitem"."product_id" ASC,
"orders_inventoryitem"."producer_id" ASC,
"orders_inventoryitem"."inventory_date" ASC'}
So is the first generated SQL a bug? Or am I still missing
something?
(And still hunting for a better (or any clean) way to accomplish my
goal...)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---