3👍
✅
You can do this using the model’s query capabilities.
Here’s an example for the monthly query:
from django.db.models import Avg
Table.objects.extra(select={'month':"strftime('%m',date)"}).values('month').annotate(Avg('value'))
Where you may want to change strftime('%m',date)
with month(date)
or any other calculation, depending on your database datetime functionality.
Source:stackexchange.com