0
我有一個觀點:從URLDjango的合計不返回任何值
class ExpenseDateFilterTotal(APIView):
def post(self, request, format=None):
queryset = Expenses.objects.all().aggregate(total=Sum('day'))
return HttpResponse(queryset, content_type="application/json")
訪問:
url(r'^expenses_date_filter_total/$', expenses.ExpenseDateFilterTotal.as_view()),
我期待等於迴應:
{"total":234}
但所有我得到的是:
total
我是django的新手,我讀https://docs.djangoproject.com/en/1.10/topics/db/aggregation/的api文檔。 count()函數完美運行。但總和/平均/最大等不是。
哦,非常感謝你。你爲我節省了幾個小時的工作。 –