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

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -