문제

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
도움이 되었습니까?

해결책

You need to import Sum first:

from django.db.models import Sum
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top