aggregate can only generate one aggregate value.
You can get the total hours of the current month at the following request.
from datetime import datetime this_month = datetime.now().month HourEntries.objects.filter(date__month=this_month).aggregate(Sum("quantity"))
So, to get aggregated HourEntry values ββfor all months, you can program the query for all months in db. But it is better to use raw sql.
HourEntries.objects.raw("select date_format(date, '%Y-%m') as month, sum(quantity) as hours from hourentries group by date_format(date, '%Y-%m') order by date;")
source share