如何查询计数?
我有一个查询,
Bid.objects.filter(shipment=shipment, status=BidStatuses.ACCEPTED, user=request.user, items__count=0).exists()
不起作用的部分是 items__count=0
。出价与项目具有多对多的关系。我需要检查此出价是否有 0 件商品。我怎样才能做到这一点?
I've got a query,
Bid.objects.filter(shipment=shipment, status=BidStatuses.ACCEPTED, user=request.user, items__count=0).exists()
The part that doesn't work is items__count=0
. Bids have a many-to-many relationship with items. I need to check if this bid has 0 items. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
聚合。
http://docs.djangoproject.com/en/1.2/topics/db/聚合/
查看文档,阅读示例,你会找到答案
Aggregation.
http://docs.djangoproject.com/en/1.2/topics/db/aggregation/
see the doc upon, read the sample,you will find the answer
作为记录(已经有一个接受的答案,带有 Django 聚合文档的链接),OP 需要的是:
For the record (there is already an accepted answer with a link to Django aggregation docs), what OP needs is: