A new model field option doesn't seem necessary. I think a cleaner solution 
would be something like a decorator that takes a list of fields, e.g.

@repr_fields('first_name', 'last_name')
class Person(...):
     ...

This doesn't need to live in Django itself though.

On Thursday, June 23, 2016 at 7:30:50 PM UTC-4, Ben Friedland wrote:
>
> Has a feature like this ever been considered? 
>
> If a model has no __unicode__, __str__ or __repr__ representation, then 
> maybe it could devise a string representation by collecting fields which 
> have this value set to True. 
>
> Example:
>
> Without the feature:
>
> class Person(models.Model):
>      first_name = models.CharField(max_length=50)
>      last_name = models.CharField(max_length=50)
>
> >>> person = Person(first_name='Ben', last_name='Friedland')
> >>> print person
> <Person: Person object>    # fairly useless object representation
>
>
> This feature would work something like: 
>
> class Person(models.Model):
>      first_name = models.CharField(max_length=50, *repr_output=True*)
>      last_name = models.CharField(max_length=50, *repr_output=True*)
>
> >>> person = Person(first_name='Ben', last_name='Friedland')
> >>> print person
> <Person: first_name='Ben', last_name='Friedland'>   # includes fields 
> specified via repr_output=True
>
> If this would be useful I'd be happy to formally create an issue and even 
> implement the feature. 
>
> Thanks!
>
> Ben Friedland
> www.bugben.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 post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/b018a812-c773-4766-97fe-f15969592fb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to