On Tue, 2007-12-11 at 04:39 -0800, l5x wrote:
[...]
> change it to:
> 
>     def __unicode__(self):
>         return smart_unicode(self.ticket_numb)

You were going so well on the "good advice" front up until here... :-)

A __unicode__() method if one of the few places where smart_unicode() is
inappropriate. You should use force_unicode() if you need that function
(in the case at hand, we can save time and just call unicode() directly,
but that's beside the point here).

The reason for preferring/requiring force_unicode() here is if the thing
you are converting is a delayed translation --- something marked with
ugettext_lazy(), for example. The smart_unicode() method leaves a lazy
translation as a lazy translation object, whereas force_unicode() forces
the object to a unicode string. This is why you usually want to call
smart_unicode(): it won't prematurely convert lazy translations to their
string form. However, a __unicode__ method is one place where you
absolutely *must* return a string, not something that might grow up to
be a string one day. So you should use force_unicode() there.

All this is, of course, a moot point if you know the thing you're
converting isn't a lazy translation, which is often the case in a
model's __unicode__(), but it's a good habit to get into in any case.

Regards,
Malcolm

-- 
Monday is an awful way to spend 1/7th of your life. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to