1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-26 21:14:19 +00:00

Add ColRepr to alchemist

This commit is contained in:
Steffo 2020-11-03 16:40:54 +01:00
parent 831aa0bad8
commit 0fa1a90360
2 changed files with 13 additions and 0 deletions

View file

@ -1 +1,2 @@
from .func import *
from .repr import *

View file

@ -0,0 +1,12 @@
class ColRepr:
"""A mixin that can be added to a declared class to display all table columns in the __repr__."""
def __repr__(self):
columns = [c.name for c in self.__class__.__table__.columns]
args = [f"{c}={repr(self.__getattribute__(c))}" for c in columns]
return f"{self.__class__.__qualname__}({', '.join(args)})"
__all__ = (
"ColRepr",
)