Changes between Initial Version and Version 1 of Ticket #15239
- Timestamp:
- Feb 8, 2011, 8:12:49 AM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #15239
- Property Resolution → duplicate
- Property Status new → closed
-
Ticket #15239 – Description
initial v1 1 1 Hello. I created two querysets which works fine. 2 2 {{{ 3 3 Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(Q(mysum__lte=F('invoice_total')) ) 4 4 Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(mysum=None) 5 5 }}} 6 6 queryset1 returns objects with mysum less then invoice_total. mysum sums payments for the particular invoice. 7 7 queryset2 catches non-numeric objects with 'None' as mysum value. This happens when there no payments for the particular invoice. … … 9 9 Fields used: 10 10 invoice_total is a decimal field. 11 payments __payment is also decimal (in related_set).11 payments!__payment is also decimal (in related_set). 12 12 13 13 Now to combine those two querysets into one i use Q logic. 14 14 {{{ 15 15 Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(Q(mysum=None) | Q(mysum__lte=F('invoice_total')) ) 16 16 }}} 17 17 18 18 Unfortunatly 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).