1👍
✅
Try this:
Download.objects.filter(download_date__range=[date_1, date_2]).values('song').annotate(downloads = Count('id'))
0👍
You must change order_by
. Explained here https://docs.djangoproject.com/en/dev/topics/db/aggregation/#interaction-with-default-ordering-or-order-by
res = Download.objects.filter(download_date__range=[date_1, date_2])\
.annotate(downloads=Count('song'))\
.values('downloads', 'song')\
.order_by()
- [Answer]-Next upcoming date model object ignoring past dates
- [Answer]-Django Site Migration Issue
- [Answer]-How do I populate the Django table MyApp_user_groups in a yaml fixture?
Source:stackexchange.com