#4921: django.contrib.admin calls str() on model instances, not unicode()
------------------------------------------------------+---------------------
Reporter: Ludvig Ericson <[EMAIL PROTECTED]> | Owner: adrian
Status: new | Component: Admin
interface
Version: SVN | Keywords: admin
unicode listing
Stage: Unreviewed | Has_patch: 0
------------------------------------------------------+---------------------
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:
{{{
#!python
>>> 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:
{{{
#!python
class MyModel(models.Model):
some_field = models.CharField()
def __unicode__(self):
return u"foo: %s" % (self.some_field,)
__str__ = lambda s: str(s.__unicode__())
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/4921>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---