On Fri, Aug 28, 2009 at 2:49 AM, Léon Dignòn <leon.dig...@gmail.com> wrote:
> > Hi, > > I don't exactly understand the difference between ugettext() and > ugettext_lazy(). I read the documentation and I've read that > ugettext_lazy translates a string on access. Sounds more efficient. > But why do I get this error on that code? > > from django.db import models > from django.utils.translation import ugettext_lazy as _ > > class Country(models.Model): > name = models.CharField(max_length=256, unique=True) > name_iso_2 = models.CharField(max_length=2, unique=True, > help_text='http://de.wikipedia.org/wiki/ISO-3166-1-Kodierliste') > name_iso_3 = models.CharField(max_length=3, unique=True, > help_text='http://de.wikipedia.org/wiki/ISO-3166-1-Kodierliste') > > def __unicode__(self): > return _(self.name) > > > > Exception Type: TemplateSyntaxError at /admin/skins/country/ > Exception Value: Caught an exception while rendering: coercing to > Unicode: need string or buffer, __proxy__ found Python's unicode function must return a unicode object. If your __unicode__ implementation does not return a unicode object then Python coerces it to unicode. But there are only a limited number of types that Python can coerce to unicode (strings and buffers, or so the message implies). So if you return neither a unicode object, nor a string or buffer, then you get this error. There are places where ugettext_lazy cannot be used. This would appear to be one of them. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---