views:

134

answers:

1

Hi,

I defined a unicode() method in my Contact model.

def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name)

Now I want to show the return value of the unicode() method in a template.

But all that i try fails.

{{ object.unicode }}

or

{{ object.unicode() }}

or

{{ object.__unicode__ }}

or

{{ object.str }}

That confuses me since I have another Model level function which can be referenced to from the template without problems.

This works fine:

def get_id(self):
        return "%i" % self.id 

{{ object.get_id|escape }}
+5  A: 
{{ object }}

(and some more characters so SO doesn't complain)

Ignacio Vazquez-Abrams
Great. Thanks. That works. But what do you mean with "(and some more characters so SO doesn't complain)"
Tom Tom
SO requires a minimum of 15 characters in an answer or comment.
Ignacio Vazquez-Abrams
ah ok :D got it
Tom Tom