[Django]-Django Monthly/quartarly grouping of DateField() data

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.

Leave a comment