shellfly / django-vote

Simple vote for django
http://django-vote.readthedocs.io
Apache License 2.0
158 stars 49 forks source link

Best way to get a sum of all votes for a given filter query? #58

Closed perrierism closed 7 years ago

perrierism commented 7 years ago

Assuming a votable object has an "author" field, is there an easy query to get the sum votes for a given "author" across all instances of a votable object?

The aim is similar to finding a user's "karma" on reddit; a query for the sum of all upvotes on all objects for which the user is author ... is there an efficient way to do this?

perrierism commented 7 years ago
from django.db.models import Count
models.Comment.objects.filter(author=theuser).aggregate(Count('vote_score'))['vote_score__count']