想实现id相等并且某个字段非空,网上是这样的,
filterList = []
if name is not None:
filterList.append(Role.name.like('%'+name+'%'))
if gender is not None:
filterList.append(Role.gender == gender)
if attribute is not None:
filterList.append(Role.attribute == attribute)
if site is not None:
filterList.append(Role.site == site)
role = Role.query.filter(*filterList).all()
其实直接用逗号隔开不同的条件也可以的:
Order.query.filter(Order.ID==ID, Order.title.isnot(None)).all()
但是这样好像不能实现or查询。。