从外键的另一侧接近模型
使用Django 文档示例博客
和 Entry
模型,如何获取所有具有 name = "a"
并且不与任何实例关联的 Blog
对象的查询集Entry
模型的?
用原始 (My)SQL 术语来说,Django ORM 相当于:
SELECT * FROM blog_table bt
WHERE bt.name='a' AND bt.id NOT IN (SELECT et.blog_id FROM entry_table et)
Working with Django docs' sample Blog
and Entry
models, how would one get a queryset of all Blog
objects that have name = "a"
and that are not associated with any instance of the Entry
model?
In raw (My)SQL terms, what is the Django ORM equivalent of:
SELECT * FROM blog_table bt
WHERE bt.name='a' AND bt.id NOT IN (SELECT et.blog_id FROM entry_table et)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要的是具有
name = "a"
并且没有任何关联条目的Blog
实例列表。您可以通过以下方式执行此操作:What you need is a list of
Blog
instances that havename = "a"
and do not have any associated entries. You can do this by: