aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models/utils.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2019-04-19 18:23:06 +0100
committerGravatar Gareth Coles <[email protected]>2019-04-19 18:23:06 +0100
commit0cd78b638c48ac14c592398da0ed19f3e5ca2e2e (patch)
treed74ebdf98537a6dd65dc926bcc3fed1458515c93 /pydis_site/apps/api/models/utils.py
parentChar input has placeholder, finish dir listing (diff)
parentRevert linter to non-verbose. (diff)
Merge branch 'django' into django+200/wiki
# Conflicts: # Pipfile.lock # pydis_site/apps/home/tests.py
Diffstat (limited to 'pydis_site/apps/api/models/utils.py')
-rw-r--r--pydis_site/apps/api/models/utils.py20
1 files changed, 20 insertions, 0 deletions
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})>'