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.
π€Andrew Gorcester
- [Django]-How can I add choices to a timefield in a Django form?
- [Django]-Deploying Django, supervisorctl abnormal termination
Source:stackexchange.com