django.contrib.admin ignores __str__ on model instances
|Reported by:||Owned by:||Adrian Holovaty|
|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.
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
|Patch needs improvement:||unset|
comment:3 Changed 9 years ago by
|Summary:||django.contrib.admin calls str() on model instances, not unicode() → django.contrib.admin ignores __str__ on model instances|