Sqlalchemy Automap - Adding Methods To Automapped Model
I have a preexisting database that I'm using with SQLAlchemy, so I'm using automap to get the Models from the database. What is the best way to add methods to these classes? For ex
Solution 1:
Specify your classes explicitly beforehand, and define your methods as you would normally:
Base = automap_base()
classUser(Base):
__tablename__ = 'user'defverify_password(self, password):
...
Base.prepare(engine, reflect=True)
Now Base.classes.User
and User
are the same, with your additional methods. To make your User
class flask-login compatible, implement the listed attributes and methods, or add the provided UserMixin
to your User
class. The mixin seems to only expect the existence of an id
attribute/column from your User
class.
Post a Comment for "Sqlalchemy Automap - Adding Methods To Automapped Model"