I have two tables user and user_us which has the same structure. I tried to use a class and an inherited class to access both using declared attribute decoration. If the table which gets accessed does not change by this declared attribute then what is the point of doing it? What am I doing wrong?
class User(db.Model):
@declared_attr
def __tablename__(cls) -> str:
return str(cls.__name__.lower())
id = db.Column(db.Integer, primary_key=True)
class User_us(User):
pass
print(f'Test state: {User_us.__tablename__} {(User_us.__table__.name)}')
gives output:
Test state: user_us user
I was expecting:
Test state: user_us user_us and the table accessed to be of user_us.