Flask SQLAlchemy用“不等于”查询列
我可以在我的Seat桌子上查询未分配邀请的所有席位:
seats = Seat.query.filter_by(invite=None).all()但是,当查询分配了邀请的所有座位时,我得到了NameError:
seats = Seat.query.filter_by(invite!=None).all()NameError: name 'invite' is not defined
这是我的Seat课:
class Seat(db.Model): id = db.Column(db.Integer, primary_key=True)
invite_id = db.Column(db.Integer, db.ForeignKey('invite.id'))
invite = db.relationship('Invite',
backref=db.backref('folks', lazy='dynamic'))
如何查询所有者不为空的所有席位?
回答:
该filter_by()方法采用一系列关键字参数,因此你始终必须使用=它。
你要使用filter()允许的方法!=:
seats = Seat.query.filter(Seat.invite != None).all()以上是 Flask SQLAlchemy用“不等于”查询列 的全部内容, 来源链接: utcz.com/qa/434664.html

