Flask SQLAlchemy querying a column with “not equals”

后端 未结 2 1001
深忆病人
深忆病人 2020-12-24 10:31

I can query my Seat table for all seats where there is no invite assigned:

seats = Seat.query.filter_by(invite=None).all()

How

2条回答
  •  误落风尘
    2020-12-24 10:56

    I think this can help http://docs.sqlalchemy.org/en/rel_0_9/core/sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.isnot

    Is None

    query.filter(User.name == None)
    

    or alternatively, if pep8/linters are a concern

    query.filter(User.name.is_(None))

    Is not None

    query.filter(User.name != None)
    

    or alternatively, if pep8/linters are a concern

    query.filter(User.name.isnot(None))

提交回复
热议问题