I'm trying to retrieve all Inventory Items whose onhand quantity is
greater than zero, OR (whose date is within a specified range AND
whose received quantity is zero).

InventoryItems have three relevant fields for this query: onhand,
inventory_date, and received.

I currently have only 2 inventory items, only one of which matches the
desired criteria.

If I specify the following two separate queries, I get the correct
results from each query:

1. items = InventoryItem.objects.filter(Q(onhand__gt=0) )
...correctly returns an empty list (currenly no items have onhand
quantities).

2. items = InventoryItem.objects.filter(
        Q(inventory_date__range=(weekstart, thisdate),
received__exact=0))
...correctly returns a list containing one item.

If I put the clauses together like this:
items = InventoryItem.objects.filter(
     Q(onhand__gt=0) |
         Q(inventory_date__range=(weekstart, thisdate),
received__exact=0))
...I do not get the expected result (one item), but rather 2 items,
including one that violates both clauses.

But if I put these clauses together like this (omitting the date
range):
items = InventoryItem.objects.filter(
     Q(onhand__gt=0) |
         Q(received__exact=0))
...I get the correct result.

So I assume I do not understand something about either this clause:
    Q(inventory_date__range=(weekstart, thisdate), received__exact=0)
or how to combine it into a larger set of filter clauses with an OR.

I thought it was ANDing the first part with the last part, and that is
how it seems to act on its own.  But it behaves differently when
combined in a larger filter with an OR.

So what am I missing?  Or, is there a better 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 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