gpt4 book ai didi

python - 通过比较原因错误进行属性过滤

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:16 26 4
gpt4 key购买 nike

型号:

class Thing(db.Model):
__tablename__ = 'things'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
type_id = db.Column(db.Integer, db.ForeignKey('types_of_things.id'))

class TypeOfThing(db.Model):
__tablename__ = 'types_of_things'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64))
number = db.Column(db.Integer)
things = db.relationship('Thing', backref='type', lazy='dynamic')

尝试:

Thing.query.join(TypeOfThing).filter_by(Thing.type.number<=1).first()

原因:

AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Thing.type has an attribute 'number'

尝试:

Thing.query.join(TypeOfThing).filter_by(number<=1).first()

原因:

NameError: name 'number' is not defined

最佳答案

看来我需要这样做:

Thing.query.join(TypeOfThing).filter(TypeOfThing.number<=1).first()

关于python - 通过比较原因错误进行属性过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com