2011-10-06 39 views
5

tôi có các bảng bảng:AttributeError: đối tượng 'InstrumentedList' không có thuộc tính

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 

Khi tôi cố gắng chạy này, tôi nhận được mã lỗi này trong "nếu giá trị là True" khoản:

AttributeError: 'InstrumentedList' object has no attribute 'upvotes' 

Tôi đã thử cung cấp cho Voteinfo ID duy nhất của riêng nó và thêm uselist = False vào mối quan hệ. Tôi đã thử thay thế mối quan hệ thành thứ từ VoteThing thành Voteinfo, nhưng điều đó cũng không giúp được gì. Tôi không biết InstrumentedList là gì. Chuyện gì vậy?

+0

vì 'điều' là tham số cho' __init__', có lẽ bạn đang chuyển nó khi bạn khởi tạo VoteThing. Vậy bạn đang đi qua cái gì? –

+0

Vâng, tôi đang đi qua một điều: thing1 = Thing(), user1 = Người dùng(), voteinfo1 = Voteinfo (thing1), votething1 = VoteThing (user1, thing1, True) –

Trả lời

Các vấn đề liên quan