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

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

javascript - jquery or ashx not working -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -