diff options
author | 2020-07-14 14:21:16 +0200 | |
---|---|---|
committer | 2020-07-14 14:21:16 +0200 | |
commit | 1f4beeb10ccec010aa2d503ed73b4b64e9c1895f (patch) | |
tree | 0114b9a6c6aaf907ceceb4c8d631f7d5e9528bd9 /pydis_site/apps/api/models/mixins.py | |
parent | Catch ConnectionError when trying to get updated repository data (diff) |
Rename utils.py to mixins.py. More precise.
https://github.com/python-discord/site/issues/305
Diffstat (limited to 'pydis_site/apps/api/models/mixins.py')
-rw-r--r-- | pydis_site/apps/api/models/mixins.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pydis_site/apps/api/models/mixins.py b/pydis_site/apps/api/models/mixins.py new file mode 100644 index 00000000..0540c4de --- /dev/null +++ b/pydis_site/apps/api/models/mixins.py @@ -0,0 +1,17 @@ +from operator import itemgetter + + +class ModelReprMixin: + """Mixin providing a `__repr__()` to display model class name and initialisation parameters.""" + + def __repr__(self): + """Returns the current model class name and initialisation parameters.""" + 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})>' |