我需要检索月份名称和相应月份的总价。下面是我的订单表示例
我的尝试是:
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')}]
如何解决这个问题?
https://stackoverflow.com/questions/51335570
复制相似问题