1👍
✅
Create in your User
model methods, that count the precentage and then simply use it as needed:
class User(...):
...
def count_star_precentage(self, star):
return (Rating.objects.filter(activity__creator=self, star=star).count() / self.all_ratings().count()) * 100
def all_ratings(self):
return Rating.objects.filter(activity__creator=self)
With them you can get precentage with simple call:
user = User.objects.get(id=some_id)
user.count_star_precentage(3) # it will give the percent of total ratings with 3 star given by that user
Source:stackexchange.com