在官方的Django文档中,有关从查询集中排除的部分(https://docs.djangoproject.com/en/dev/ref/models/querysets/#exclude),有几个查询的解释:
此示例排除pub_date晚于2005-1-3并且标题为“Hello”的所有条目:
Entry.objects.exclude(pub_date__gt=datetime.date(2005, 1, 3), headline='Hello')
在SQL术语中,评估为:
SELECT ...
WHERE NOT (pub_date > '2005-1-3' AND headline = 'Hello')
此示例排除pub_date晚于2005-1-3或其标题为“Hello”的所有条目:
Entry.objects.exclude(pub_date__gt=datetime.date(2005, 1, 3)).exclude(headline='Hello')
在SQL术语中,评估为:
SELECT ...
WHERE NOT pub_date > '2005-1-3'
AND NOT headline = 'Hello'
请注意,第二个示例更具限制性。
最后一个对我来说并不清楚。我看不出第一个和第二个之间的区别,有人可以解释一下吗?