Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. The easiest way to order by ratings is to add a GenericRelation to the Rating model from your model:
  2.  
  3. from django.contrib.contenttypes.fields import GenericRelation
  4. from star_ratings.models import Rating
  5.  
  6. class Foo(models.Model):
  7. bar = models.CharField(max_length=100)
  8. ratings = GenericRelation(Rating, related_query_name='foos')
  9.  
  10. Foo.objects.filter(ratings__isnull=False).order_by('ratings__average')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement