我想在排除语句中进行“与”或运算。
喜欢:
Select all those records where name is NOT Mason and Status is NOT Unactive
或
Select all those records where name is NOT Mason and Status is active
尝试过。
Users.objects.exclude(name="Mason", active=False)
但这不是OR
运算,而是AND
。如何进行OR
运算。
最佳答案
为了通过 OR 运算使用排除。您必须使用排除两次。
Entry.objects.exclude(pub_date__gt=datetime.date(2005, 1, 3)).exclude(headline='Hello')
或
User.objects.exclude(name="Mason").exclude(active=False)
引用
关于Django ORM,排除两个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22983949/