如何在Django查询集中找到不在另一个指定查询集中的实体? [英] How does one find the entities in a Django query set that are not in another specified query set?
本文介绍了如何在Django查询集中找到不在另一个指定查询集中的实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有两个Django查询集,一个包含占用会话1的课程的Django查询集(A组),其中包括课程2(设置B)的课程:
A = session1.courses.all )
B = session2.courses.all()
这两个之间有很多重叠查询集。
什么是获取集合B中的一组课程的有效方法,但不是集合A?
$ b $我相信这相当于从集合B中取出两组的交集。
谢谢!
解决方案
A.exclude(pk__in = B)
应该工作
I am using Django to develop a course registration site for an educational institution.
Suppose I have two Django query sets, one that comprises of courses that occupy session 1 (set A) and one that comprises of courses in session 2 (set B):
A = session1.courses.all()
B = session2.courses.all()
There is much overlap between these two query sets.
What is an efficient way to obtain the set of courses within set B, but not in set A?
I believe this is equivalent to taking out the intersection of the two sets from set B.
Thank you!
解决方案
A.exclude(pk__in = B)
should work
这篇关于如何在Django查询集中找到不在另一个指定查询集中的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文