155👍
✅
Try this:
Rating.objects.filter(attribute__in=attributes) \
.values('location') \
.annotate(score = Sum('score')) \
.order_by('-score')
41👍
Can you try this.
Rating.objects.values('location_id').filter(attribute__in=attributes).annotate(sum_score=Sum('score')).order_by('-score')
- [Django]-How can one use enums as a choice field in a Django model?
- [Django]-How to make Django serve static files with Gunicorn?
- [Django]-How to use permission_required decorators on django class-based views
Source:stackexchange.com