Changes between Initial Version and Version 1 of Ticket #15239


Ignore:
Timestamp:
Feb 8, 2011, 8:12:49 AM (14 years ago)
Author:
Russell Keith-Magee
Comment:

Duplicate of #15240

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #15239

    • Property Resolutionduplicate
    • Property Status newclosed
  • Ticket #15239 – Description

    initial v1  
    11Hello. I created two querysets which works fine.
    2 
     2{{{
    33Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(Q(mysum__lte=F('invoice_total')) )
    44Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(mysum=None)
    5 
     5}}}
    66queryset1 returns objects with mysum less then invoice_total. mysum sums payments for the particular invoice.
    77queryset2 catches non-numeric objects with 'None' as mysum value. This happens when there no payments for the particular invoice.
     
    99Fields used:
    1010invoice_total is a decimal field.
    11 payments__payment is also decimal (in related_set).
     11payments!__payment is also decimal (in related_set).
    1212
    1313Now to combine those two querysets into one i use Q logic.
    14 
     14{{{
    1515Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(Q(mysum=None) | Q(mysum__lte=F('invoice_total')) )
    16 
     16}}}
    1717
    1818Unfortunatly it doesnt work (returned queryset is empty). In sql log i can see that those two conditions above are always being glued with default AND (should be ORed because I use Q | Q, not Q & Q).
Back to Top