gpt4 book ai didi

Django ORM,排除两个值

转载 作者:行者123 更新时间:2023-12-02 21:28:14 25 4
gpt4 key购买 nike

我想在排除语句中进行“与”或运算。

喜欢:

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)

引用

Docs

关于Django ORM,排除两个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22983949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com