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 the default for a Django model. Are there any 
implications for changing it to this?

Regards,

Fabian

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/8da8ae9b-b13d-4c05-9634-543cd4e1cbe3n%40googlegroups.com.


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() includes the class name (twice) and PK.

On Fri, 18 Jun 2021 at 15:58, Fabian Jarrett 
wrote:

> 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 the default for a Django model. Are there any
> implications for changing it to this?
>
> Regards,
>
> Fabian
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/8da8ae9b-b13d-4c05-9634-543cd4e1cbe3n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM3t9gim4YQXi5t-AjZEKtqcShmrKSSko7Kkj1Lumn8ntQ%40mail.gmail.com.