Changing the models default __repr__

2021-06-18 Thread Fabian Jarrett
Hi, I was asking on discord what others use as a __repr__ naming convention for models and someone suggested: def __repr__(self): return f'<{self.__class__.__name__} pk={self.pk}>' https://discord.com/channels/159039020565790721/159041895077642251/855456770548564018 Feels like it should be

Re: Changing the models default __repr__

2021-06-18 Thread 'Adam Johnson' via Django developers (Contributions to Django itself)
Model defines these defaults: def __repr__(self): return '<%s: %s>' % (self.__class__.__name__, self) def __str__(self): return '%s object (%s)' % (self.__class__.__name__, self.pk) The repr includes "self", which will call __str__, which includes self.pk. So the default repr