Re: Django Model Fields a repr_output property, to include a field in the string representation of an object

2016-07-01 Thread Erik Cederstrand
Plus, it's 3 lines of code and faster to implement than to look up the 
documentation:


class ReprFieldsMixIn:
  class Meta:
  repr_fields = ('bar', 'baz')

  def __repr__(self):
  '<%s: %s>' % (self.__class__.__name__, ', '.join('%s=%s' % (f, 
repr(getattr(self, f))) for f in self._meta.repr_fields))


Erik

> Den 1. jul. 2016 kl. 21.52 skrev Tim Graham :
> 
> Since no one else expressed interest in two weeks, I think it's safe to say 
> it isn't a use case for 80% of users. That's the rough bar I think of as to 
> whether or not something needs to be in core.
> 
> On Friday, July 1, 2016 at 3:05:13 PM UTC-4, Ben Friedland wrote:
> Well in that case wouldn't it make sense to add it to the meta class? Just 
> like how there's unique_together, etc., there could be repr_fields. In which 
> case I think it would be great if it were part of Django. 
> 
> Maybe reconsider as a part of the meta class?
> 
> Ben Friedland
> www.bugben.com
> 
> On Monday, June 27, 2016 at 6:24:57 AM UTC-7, Tim Graham wrote:
> 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
> # 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
># 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/08be43ef-ef2e-4a62-bf17-a33935ab207b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/728D4B02-C3B0-436A-A661-9CC16437A55A%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Django Model Fields a repr_output property, to include a field in the string representation of an object

2016-07-01 Thread Tim Graham
Since no one else expressed interest in two weeks, I think it's safe to say 
it isn't a use case for 80% of users. That's the rough bar I think of as to 
whether or not something needs to be in core.

On Friday, July 1, 2016 at 3:05:13 PM UTC-4, Ben Friedland wrote:
>
> Well in that case wouldn't it make sense to add it to the meta class? Just 
> like how there's unique_together, etc., there could be repr_fields. In 
> which case I think it would be great if it were part of Django. 
>
> Maybe reconsider as a part of the meta class?
>
> Ben Friedland
> www.bugben.com
>
> On Monday, June 27, 2016 at 6:24:57 AM UTC-7, Tim Graham wrote:
>>
>> 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
>>> # 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
>>># 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/08be43ef-ef2e-4a62-bf17-a33935ab207b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Model Fields a repr_output property, to include a field in the string representation of an object

2016-07-01 Thread Ben Friedland
Well in that case wouldn't it make sense to add it to the meta class? Just 
like how there's unique_together, etc., there could be repr_fields. In 
which case I think it would be great if it were part of Django. 

Maybe reconsider as a part of the meta class?

Ben Friedland
www.bugben.com

On Monday, June 27, 2016 at 6:24:57 AM UTC-7, Tim Graham wrote:
>
> 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
>> # 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
>># 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/bf6be26f-a27b-46a6-a51a-f4e092a29b6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.