further improved representational methods
This commit is contained in:
parent
10193be983
commit
003f4cd3be
@ -1,15 +1,22 @@
|
||||
from the_works.database import db
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
import sys
|
||||
|
||||
# add method to sqlalchemy.orm.decl_api.Model
|
||||
def _asdict(self):
|
||||
return {col.key: "<BLOB>" if type(col.type) == db.types.BLOB else self.__getattribute__(col.key) for col in self.__table__.c}
|
||||
d = {}
|
||||
for col in self.__table__.c:
|
||||
if type(col.type) == db.types.BLOB:
|
||||
d[col.key] = "NULL" if self.__getattribute__(col.key) == None else f"Blob ({sys.getsizeof(self.__getattribute__(col.key))} Bytes)"
|
||||
else:
|
||||
d[col.key] = self.__getattribute__(col.key)
|
||||
return d
|
||||
db.Model._asdict = _asdict
|
||||
|
||||
# override repr() method from sqlalchemy.orm.decl_api.Model
|
||||
def __repr__(self):
|
||||
return str(self._asdict())
|
||||
return f"Titelbild({str(self._asdict())})"
|
||||
db.Model.__repr__ = __repr__
|
||||
|
||||
class Text(db.Model):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user