added __repr__() and _asdict() methods to "Model" baseclass; changed indentation from 4 to 2
This commit is contained in:
parent
e45e45f025
commit
7dc191dcab
@ -2,9 +2,19 @@ from the_works.database import db
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
|
||||
# override/add __repr__() and _asdict() methods from sqlalchemy.orm.decl_api.Model for easier handling of table rows
|
||||
def __repr__(self):
|
||||
return str({col.key: self.__getattribute__(col.key) for col in self.__table__.c})
|
||||
|
||||
def _asdict(self):
|
||||
return {col.key: self.__getattribute__(col.key) for col in self.__table__.c}
|
||||
|
||||
db.Model.__repr__ = __repr__
|
||||
db.Model._asdict = _asdict
|
||||
|
||||
|
||||
class Text(db.Model):
|
||||
__table__ = db.Model.metadata.tables['Text']
|
||||
|
||||
reihe = relationship("Reihe", back_populates="text")
|
||||
textform = relationship("Textform", back_populates="text")
|
||||
sprache = relationship("Sprache", back_populates="text")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user