blob: 731486e72a2dd4f85e0e03f9a0e2745ca8a0bcda (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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})>'
|