Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__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??

like image 950
weijia.wang Avatar asked Jul 14 '15 17:07

weijia.wang


1 Answers

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.

like image 160
x squared Avatar answered Nov 15 '22 22:11

x squared