python - django get sum of column based on where clause -


i have read documentation related django aggregation still have trouble figuring out how can sum of points per user.

here tried:

modelname.objects.filter(username=ruser.username).aggregate(sum('points')) 

i following error:

request method: request url:    http://localhost:8001/mypage/ django version: 1.4.8 exception type: nameerror exception value:     global name 'sum' not defined 

you need import sum first:

from django.db.models import sum 

Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -