weijia.wang
weijia.wang

Reputation: 2168

__unicode__(self) for python3 and Django1.8 not working

use python3 and Django1.8 admin.py to manage DB:

  class Employee(models.Model):

       name = models.CharField(max_length=20)

       sex = models.CharField(max_length=1,choices=sex_choices)

       def __unicode__(self):

           return self.name

i want return object's name,so i use __unicode__(self) return self.name

but result: enter image description here

it's only show object ,not the name!!!!

what should i do??

Upvotes: 7

Views: 2488

Answers (1)

x squared
x squared

Reputation: 3354

I believe, in python 3 with django you need to define __str__() instead of __unicode__().

I found information about this in section "__str__() and __unicode__() methods" here.

Upvotes: 20

Related Questions