[Answered ]-Implimenting a ranking algorithm in Django query

1👍

Finally figured it out, after checking django documenation. It says here

"Combining multiple aggregations with annotate() will yield the wrong results because joins are used instead of subqueries:"

So the soluction was to change to annotate to include distinct=True in the Count like such

).annotate(total_votes=Count('userUpVotes', distinct=True) - Count('userDownVotes', distinct=True)).order_by('-total_votes')

Leave a comment