flask多條件查詢並的簡單方式,

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章