diff options
author | 2019-04-16 14:16:38 +0200 | |
---|---|---|
committer | 2019-04-16 14:16:38 +0200 | |
commit | da7a5701f1dae277aab4c4947fe7d23fe02987bd (patch) | |
tree | f8f8c683664a02a9fd1860c8bb99b6645e74a651 /pydis_site/apps/api/models/utils.py | |
parent | refactoring slightly to use a class-based view, changing home to main. Ready ... (diff) | |
parent | Merge pull request #207 from python-discord/api/split-models (diff) |
merging in changes from the main branch
Diffstat (limited to 'pydis_site/apps/api/models/utils.py')
-rw-r--r-- | pydis_site/apps/api/models/utils.py | 20 |
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})>' |