0

In this example i have the following model in django:

class Test(models.Model):

    name = models.models.ForeignKey('auth.user')
    amount = models.IntegerField()

in this example i have 4 instances:
test1 = Test("John",10)
test2 = Test("John",20)
test3 = Test("Eric, 30)
test4 = Test("Eric, 40)

what i want is to get a list of tuple, with the user and the total sum of amount.

testlist = (("john", 30), ("Eric", 70))

i tried the aggregate method but then i get the total amount of all the instances

Sander
  • 95
  • 2
  • 7

0 Answers0