I'm using django-simple-ratings on my project. I hook the
ratings to my
Post app, so users can vote up/down and then order it by the score. Pretty much what i want is included on the
ratings app. There's this page where i need to list all of the
Post (just like stackoverflow). But for every
Post where i display the ratings, it hit the db, and it makes the site reeeaaall slow. models.py:
from ratings.models import Ratings, RatedItemBase class PostRatings(RatedItemBase): content_object = models.ForeignKey('Post') class Post(models.Model): title = models.CharField(max_length = 200) content = models.TextField() ratings = Ratings(PostRatings) for q in Post.objects.all(): print q.ratings.cumulative_score() #or print q.postratings_set.aggregate(Sum('score'))['score__sum']
For every loop, it hit the db, another try:
for q in Post.objects.prefetch_related('postratings_set'): print q.postratings_set.aggregate(Sum('score'))['score__sum']
Still hit the db for every loop.
Does any of you have the same problem? How did you solved it? Or should i change to another ratings app? Thank you.