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:
parent
831aa0bad8
commit
0fa1a90360
2 changed files with 13 additions and 0 deletions
|
@ -1 +1,2 @@
|
||||||
from .func import *
|
from .func import *
|
||||||
|
from .repr import *
|
12
royalnet/alchemist/repr.py
Normal file
12
royalnet/alchemist/repr.py
Normal 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",
|
||||||
|
)
|
Loading…
Reference in a new issue