我想把这个查询从 SQL 放到 Django:
"select date_format(date, '%Y-%m') as month, sum(quantity) as hours from hourentries group by date_format(date, '%Y-%m') order by date;"
导致问题的部分是在聚合时按月分组。我试过这个(这似乎合乎逻辑),但没有奏效:
HourEntries.objects.order_by("date").values("date__month").aggregate(Sum("quantity"))