简体   繁体   English

与Python Flask一起使用SQLAlchemy不起作用

[英]Using or with Python Flask SQLAlchemy doesn't work

I've got a Flask app and I'm trying to get a SQLalchemy query using OR to return two different status like this but in one query: 我有一个Flask应用程序,我试图使用OR来返回一个SQLalchemy查询,以返回两个不同的状态,如下所示,但在一个查询中:

        csv_list_1 = csvTable.query.filter_by(file_uuid=file_uuid).filter_by(status="Validated")

        csv_list_2 = csvTable.query.filter_by(file_uuid=file_uuid).filter_by(status="Also Validated")

I've found a couple of answers on stack overflow but trying the following: 我在堆栈溢出中找到了两个答案,但是尝试以下操作:

from sqlalchemy import or_
csv_list = csvTable.query.filter_by(file_uuid=file_uuid).filter_by(or_(status="Validated", status="Also Validated"))

I get: 我得到:

SyntaxError: keyword argument repeated SyntaxError:关键字参数重复

I'm not sure where to go from here. 我不确定从这里去哪里。

Your column names shouldn't be keyword arguments here, it should be a boolean check like this: 您的列名不应在此处作为关键字参数,而应是布尔检查,如下所示:

csv_list = csvTable.query.filter_by(file_uuid=file_uuid)\
    .filter(or_(status == "Validated", status == "Also Validated"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM