如何将此 SQL 查询转换为 Django ORM 语句?
SELECT field1, field2, field3
FROM table1
WHERE field1 NOT IN
(SELECT 2_field1 FROM table2);
请帮忙!:)
ps
table1
并且table2
不受ForeignKey
or限制ManyToMany
使用两个 QuerySet,如文档中所示。
inner_qs = table2.objects.all()
results = table1.objects.exclude(field1__in=inner_qs)