4

I have read the documentation related to django aggregation but I am still have trouble figuring out how exactly I can get a sum of points per user.

Here is what I tried:

ModelName.objects.filter(username=rUser.username).aggregate(Sum('points'))

I get the following error:

Request Method: GET
Request URL:    http://localhost:8001/mypage/
Django Version: 1.4.8
Exception Type: NameError
Exception Value:    
global name 'Sum' is not defined

1 Answer 1

12

You need to import Sum first:

from django.db.models import Sum
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.