[Django]-Trouble with _unicode() method in django

2πŸ‘

βœ…

The django docs show you how to specify a unicode method in your model:
https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#other-model-instance-methods

class Person(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)

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

Note: These are DOUBLE underscores, where in your example you are only using single underscores.

Its a standard python special class method, as listed here

πŸ‘€jdi

3πŸ‘

They need to be named __unicode__ (two underscores on either side). This is an awkward detail of Python reserved methods that is not immediately obvious by looking at them.

Leave a comment