问题
How this SQL query can be translated to Django ORM statement?
SELECT field1, field2, field3
FROM table1
WHERE field1 NOT IN
(SELECT 2_field1 FROM table2);
Kindly help! :)
pstable1
and table2
not bounded with ForeignKey
or ManyToMany
回答1:
Using two QuerySets, as shown in the docs.
inner_qs = table2.objects.all()
results = table1.objects.exclude(field1__in=inner_qs)
来源:https://stackoverflow.com/questions/14105660/select-values-which-not-in-another-table-with-django