5
我有这些表的表:AttributeError的:“InstrumentedList”对象没有属性
class Thing(Base):
__tablename__ = 'thing'
id = Column(Integer, primary_key=True)
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
class Voteinfo(Base):
__tablename__ = 'voteinfo'
thing_id = Column(Integer, ForeignKey('thing.id'), primary_key=True)
thing = relationship('Thing', backref='voteinfo')
upvotes = Column(Integer)
downvotes = Column(Integer)
def __init__(self, thing)
self.thing = thing
class VoteThing(Base):
__tablename__ = 'votething'
id = Column(Integer, primary_key=True)
voter_id = Column(Integer, ForeignKey('voter.id'))
voter = relationship('Voter', backref='votescast')
thing_id = Column(Integer, ForeignKey('thing.id'))
thing = relationship('Thing', backref='votesreceived')
value = Column(Boolean)
def __init__(self, voter, thing, value):
if value is True:
thing.voteinfo.upvotes += 1
else:
thing.voteinfo.downvotes += 1
当我尝试运行此,我得到了“如果值为True”的条款在此错误代码:
AttributeError: 'InstrumentedList' object has no attribute 'upvotes'
我已经尝试给Voteinfo自己的唯一ID并添加uselist = False关系。我尝试用VoteThing替换Voteinfo中的关系,但这也没有帮助。我不知道InstrumentedList是什么。到底是怎么回事?
因为'thing'是'__init__'的一个参数,大概你在实例化VoteThing时传递它。那么你传递了什么? –
是的,我路过一件事: thing1 =事情(), USER1 =用户(), voteinfo1 = Voteinfo(thing1), votething1 = VoteThing(USER1,thing1,真) –