在django orm中使用汇总(sum),自定义QuerySet字段
我想使用查询,其中我不需要发票和QuerySet中的总发票数量。
Invoice.objects.aggregate(total_amount=Sum('order__order_items__amount'))
Invoice.objects.count()
如何在单个查询中处理上述查询。
I want to use query in which I need No of Invoices and Total Amount of Invoices in a Queryset.
Invoice.objects.aggregate(total_amount=Sum('order__order_items__amount'))
Invoice.objects.count()
How can I handle above queries in a single query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以计算 dintiment 主键的数量:
这将返回使用
'total_amount'
和'number_of_invoices'
的字典。You can count the number of distinct primary keys:
This will return a dictionary with
'total_amount'
and'number_of_invoices'
as keys.