Change - Optional Unicode Return Values

Created on Dec. 15, 2012, 9:33 a.m. by Hevok & updated on Dec. 15, 2012, 9:34 a.m. by Hevok

The __unicode__() method of a model can return optional values. For instance, if the values need to be returned from other models. ¶
¶
.. sourcecode:: python ¶
¶
def __unicode__(self): ¶
return (u'%s%s%s') % (self.target, ('|' if self.page_type else ''), (self.page_type if self.page_type else '')) ¶
¶
Alternatively: ¶
¶
.. sour
cecode:: python ¶
¶
def __unicode__(self): ¶
";".join([unicode(x) for x in (thing_a, thing_b, getattr(obj, "optional_attribute", None), ...etc...) if x is not None]) ¶
¶


Comment: Corrected typo for code-block directive.

Comment on This Data Unit