是否可以使用LIKE运算符多列过滤数据?
users = db.UserOPD.query\
.filter(\
db.UserOPD.alamat.like('%'+q+'%'),\
db.UserOPD.contact.like('%'+q+'%'),\
db.UserOPD.jabatan.like('%'+q+'%')\
)\
.order_by(db.UserOPD.id.desc())
答案 0 :(得分:0)
添加了or_()
函数
from sqlalchemy import or_
users = db.UserOPD.query\
.filter(\
or_(\
db.UserOPD.alamat.like('%'+q+'%'),\
db.UserOPD.contact.like('%'+q+'%'),\
db.UserOPD.jabatan.like('%'+q+'%'),\
db.UserOPD.nama.like('%'+q+'%')\
)\
)\
.order_by(db.UserOPD.id.desc())