如何从子班级访问id
?
class BaseClass:
id = 'testing'
class MyClass(BaseClass):
something = id
更具体地说,我无法从id
访问class:User
:
class BaseModel:
id = db.Column(db.Integer, primary_key=True)
class User(db.Model, BaseModel):
username = db.Column(db.String(35), nullable=False, unique=True)
followed = db.relationship(
'User',
secondary=followers,
primaryjoin=(followers.c.follower_id == id),
secondaryjoin=(followers.c.followed_id == id),
backref=db.backref('followers', lazy='dynamic'),
lazy='dynamic')
答案 0 :(得分:0)
在您的示例示例中,有一个用于测试继承的小程序:
class BaseClass:
id = 'testing'
class MyClass(BaseClass):
something = BaseClass.id
if __name__ == '__main__':
print(MyClass().something) # >> "testing"
您应该可以将id
替换为BaseModel.id
。如果没有,请报告您遇到的错误。