1👍
Sum
is a aggregate
function which means keeps in process all values for a column in match with query.
But you would like to sum current row’s 2 column.
So use
ts = F('examination_participations__total_score') + F('examination_participations__additional_score')
instead of
ts = Sum(F('examination_participations__total_score') + F('examination_participations__additional_score'))
0👍
I found following solution:
def count_sufficient_participations(self):
qs = self.annotate(
cnt_suff=Count('examination_participations', filter=Q(total_score__lte=(F('examination_participations__total_score') + F('examination_participations__additional_score')) * 2))
)
return qs
Thanks for your help.
- [Answered ]-Scaling disqus using Django, horizontal and vertical partitioning helper methods, please explain
- [Answered ]-Having problems migrating in South
- [Answered ]-Use Django's call command to start celery worker with celerybeat
- [Answered ]-Post Object or array of Objects to API
- [Answered ]-DRF – extend obtain auth token
Source:stackexchange.com