Can anyone help out with the following aggregation clause? I have an invoice and invoice_item models as shown.
class Invoice(models.Model): customer = models.ForeignKey(Customer) payments_received = models.FloatField(default=0) class Invoice_Item(models.Model): invoice = models.ForeignKey('Invoice') sub_total = models.DecimalField(blank=True, null=True, max_digits=9, decimal_places=2) I create one invoice with 2 items i = Invoice(customer=c, payments_received=260) i.save() it = Invoice_Item(invoice=1, sub_total=200) it.save() it = Invoice_Item(invoice=1, sub_total=60) it.save() When performing an aggregate with one Sum the Sum of payments_received field is correct >>> account_balance = >>> Invoice.objects.filter(customer=c).aggregate(Sum('payments_received')) >>> account_balance {'payments_received__sum': 260.0} However when I add an additional item to the aggregate clause the payments_received is doubled. >>> account_balance = >>> Invoice.objects.filter(customer=c).aggregate(Sum('invoice_item__sub_total'), >>> Sum('payments_received')) >>> account_balance {'payments_received__sum': 520.0, 'invoice_item__sub_total__sum': Decimal("260.00")} I expected the payments_received sum to always stay the same, is my understanding of aggregation flawed? Paddy --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---