For working models.Count() I am using distinct=True. It is right worked if not models.Sum().
next code right worked.
def get_queryset(self, request):
qs = super(AnswerAdmin, self).get_queryset(request)
qs = qs.annotate(
count_likes=models.Count('likes', distinct=True),
count_comments=models.Count('comments', distinct=True),
)
return qsI am added new annotation with models.Sum() and found not correct results
qs = qs.annotate(
count_likes=models.Count('likes', distinct=True),
count_comments=models.Count('comments', distinct=True),
scope=models.Sum(
models.Case(
models.When(likes__liked_it=True, then=1),
models.When(likes__liked_it=False, then=-1),
output_field=models.IntegerField()
),
),
)Even if I added attribute distinct=True to models.Sum(), it still worked not correct.
How made worked models.Sum() and models.Count() together?
Cannot resolve keyword 'scope' into field. Choices are: answers, author, author_id, count_answers, count_opinions, count_tags, date_added, date_modified, id, is_dublicated, opinions, slug, status, tags, text_question, title, views
----------------------------------