想實現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查詢。。