The __unicode__ method is meant to return a human readable representation
of the model object as a unicode.
EG:
def __unicode__(self):
return u'%(id)s' % {'id': self.vm__id}
althought not very human readable is a correct __unicode__ method.
The reason behind you wanting a int number in the __unicode__ method is
strange for me/us.
Also, creating a method just to get the object id doesnt seem too bright.
why not just object.vm__id ?
2014-07-14 23:39 GMT+01:00 Tom Evans <[email protected]>:
> On Mon, Jul 14, 2014 at 11:31 PM, Aeh. ABID <[email protected]> wrote:
> >
> > In your def __unicode__ convert the current returned int to string :
> >
> >> def __unicode__(self): # Python 3: def __str__(self):
> >> return str(self.vm_id)
> >
>
> Stop, you are making my eyes bleed!
>
> It is really fairly important that you return a unicode object from
> the __unicode__ method and not a str object.
> __unicode__ is the method that python calls when python wants to turn
> your object in to a unicode representation of it. The method takes no
> arguments, and the ONLY post-condition is that it returns a unicode
> object - it should not be too taxing to get it right!
>
> If you do not return a unicode object, strange and unpredictable
> things can happen (like AttributeError("'int' object has no attribute
> 'encode'")).
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFHbX1%2B5mn3M5Wm-V3HOcLvtdaW%2Bqh4PELm8F6fq9Fo%3Dg-tzDg%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
*monoBOT*
Visite mi sitio(Visit my site): monobotsoft.es/blog/
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CA%2BxOsGCHYsTMTsG1h%3DP%3DtyBsMH3jybVt-St%3DWKUs1uzS%2BBRmHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.