Since you want the values grouped per user, you will have to filter on the User
model and annotate
each row to include the aggregations.
Assuming that sample_table
has the model Sample
and a foreign key to User
you can do this:
from django.db.models import Sum
User.objects.annotate(total_viewed=Sum('sample__viewed'),
total_likes=Sum('sample__likes'),
total_abc=Sum('sample__abc'))
And each user row will also have the fields total_viewed
, total_likes
and total_abc
.