[英]Sqlalchemy ORM filter None and False
i try to filter my entity by column named valid
and for this i apply simple filter below我尝试按名为valid
的列过滤我的实体,为此我在下面应用简单的过滤器
session.query(Mymodel).filter(Mymodel.valid !=True)
The problem is that i have None, False, and True statement for valid field.问题是我对有效字段有 None、False 和 True 语句。
How can i do correct filter to return False and None also?我怎样才能做正确的过滤器也返回 False 和 None ?
I figured out.我想通了。
SQLAlchemy has their own magic method to compose SQL statement and it can operate with == or !=
SQLAlchemy 有自己的魔术方法来编写 SQL 语句,它可以使用== or !=
And to get None with False need to do并得到 None 与 False 需要做
session.query(or_(Mymodel.valid == False, Mymodel.valid == None)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.