J'ai ces tables :
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
Lorsque j'essaie de l'exécuter, j'obtiens ce code d'erreur dans la clause "if value is True" :
AttributeError: 'InstrumentedList' object has no attribute 'upvotes'
J'ai essayé de donner à Voteinfo son propre ID unique et d'ajouter uselist=False à la relation. J'ai essayé de remplacer la relation VoteThing par Voteinfo, mais cela n'a rien donné non plus. Je ne sais pas ce qu'est une InstrumentedList. Que se passe-t-il ?