From 5002b44c76ed66d9d1ed898b302e489473b143d0 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sun, 14 Apr 2019 21:52:41 +0200 Subject: Move models to submodules. --- pydis_site/apps/api/models/utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pydis_site/apps/api/models/utils.py (limited to 'pydis_site/apps/api/models/utils.py') diff --git a/pydis_site/apps/api/models/utils.py b/pydis_site/apps/api/models/utils.py new file mode 100644 index 00000000..731486e7 --- /dev/null +++ b/pydis_site/apps/api/models/utils.py @@ -0,0 +1,20 @@ +from operator import itemgetter + + +class ModelReprMixin: + """ + Adds a `__repr__` method to the model subclassing this + mixin which will display the model's class name along + with all parameters used to construct the object. + """ + + def __repr__(self): + attributes = ' '.join( + f'{attribute}={value!r}' + for attribute, value in sorted( + self.__dict__.items(), + key=itemgetter(0) + ) + if not attribute.startswith('_') + ) + return f'<{self.__class__.__name__}({attributes})>' -- cgit v1.2.3