Django and Aggregate: Sum of distinct values?

I am trying to do a django aggregate function, but am unable to produce the desired result.

What I've got:

income_posts.values_list('category__name','amount')
[(u'Donation', Decimal("2000.00")), (u'Paycheck', Decimal("1200.00")), (u'Donation', Decimal("1000.00"))]

Desired result:

[(u'Donation', Decimal("3000.00")), (u'Paycheck', Decimal("1200.00))]

I need to Sum the 'amount' fields that have the same category__name.

12
задан John Magistr 6 December 2010 в 22:25
поделиться