django.contrib.admin ignores __str__ on model instances
|Reported by:||Ludvig Ericson <ludvig.ericson@…>||Owned by:||adrian|
|Severity:||Keywords:||admin unicode listing|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
My apologies if this has been reported already -- I did search and couldn't find anything.
django.contrib.admin calls str() on model instances when listing them by default which is not in accordance with the new unicode change, I've defined __unicode__ on my models and not __str__. Note also:
>>> class Foo(object): ... def __str__(self): ... return "Normal python str." ... >>> unicode(Foo()) u'Normal python str.'
That is, python calls the __str__ method and converts it. Behavior verified in python 2.3, so I see no compatibility issue.
I'd guess I can make up a patch but I'm not sure if this is me being silly or if this actually is an issue.
For now I just do this:
class MyModel(models.Model): some_field = models.CharField() def __unicode__(self): return u"foo: %s" % (self.some_field,) __str__ = lambda s: str(s.__unicode__())
Change History (7)
comment:1 Changed 9 years ago by mtredinnick
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 9 years ago by SmileyChris
- Summary changed from django.contrib.admin calls str() on model instances, not unicode() to django.contrib.admin ignores __str__ on model instances