Ho questi tavoli tabelle:AttributeError: oggetto 'InstrumentedList' non ha alcun attributo
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
Quando provo ad eseguire questo, ottengo questo codice di errore nella sezione "se il valore è True" clausola:
AttributeError: 'InstrumentedList' object has no attribute 'upvotes'
Ho provato a dare a Voteinfo il proprio ID univoco e l'aggiunta di uselist = False alla relazione. Ho provato a sostituire la relazione con la cosa da VoteThing a Voteinfo, ma non è stato d'aiuto. Non so cosa sia una InstrumentedList. Cosa sta succedendo?
poiché 'cosa' è un parametro di' __init__', presumibilmente lo si passa quando si istanzia il VoteThing. Allora, cosa stai passando? –
Sì, sto passando una cosa: thing1 = Thing(), user1 = User(), voteinfo1 = Voteinfo (thing1), votething1 = VoteThing (user1, thing1, True) –