【发布时间】:2018-12-22 10:50:15
【问题描述】:
我需要用相应月份的总价检索月份名称。 这是我的订单表示例
我的尝试是:
month_wise_sales = Order.objects\
.annotate(month=ExtractMonth('created_at'))\
.values('month')\
.annotate(total_sales=Sum('total_price'))
它会返回
<QuerySet [{'month': 7, 'total_sales': Decimal('138400.00')}, {'month': 9, 'total_sales': Decimal('1150.00')}]>
我的愿望是这样的
[{'month': July, 'total_sales': Decimal('138400.00')}, {'month': September, 'total_sales': Decimal('1150.00')}]
如何解决?
【问题讨论】:
-
你需要o/p作为响应还是在模板中?
-
模板@HemanthSP
标签: sql django django-queryset django-orm