__unicode __(self)for python3和Django1.8无法正常工作

wei*_*ang 4 django python-3.x web

使用python3和Django1.8 admin.py来管理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
Run Code Online (Sandbox Code Playgroud)

我想要返回对象的名称,所以我使用__unicode__(self)returnself.name

但结果是: 在此输入图像描述

它只显示对象,而不是名称!!!!

我该怎么办??

x s*_*red 16

我相信,在使用django的python 3中,你需要定义__str __()而不是__unicode __().

我在部分中找到这方面的信息"__str __()和__unicode __()方法" 在这里.