Code

Changes between Initial Version and Version 1 of Ticket #15239


Ignore:
Timestamp:
02/08/11 06:12:49 (3 years ago)
Author:
russellm
Comment:

Duplicate of #15240

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #15239

    • Property Status changed from new to closed
    • Property Patch needs improvement unset
    • Property Needs tests unset
    • Property Needs documentation unset
    • Property Resolution changed from to duplicate
  • 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).