unicode (自我)对我不起作用。我仍然可以在管理员中看到“名字对象”。我的代码如下:
import datetime # standard python datetime module
from django.db import models # Djangos time-zone-related utilities
from django.utils import timezone
class Name(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self): # Python 3: def __str__(self):
return self.name
感谢你
答案 0 :(得分:10)
您遇到的问题是您需要在类定义中定义__unicode__
方法。
import datetime # standard python datetime module
from django.db import models # Djangos time-zone-related utilities
from django.utils import timezone
class Name(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self): # Python 3: def __str__(self):
return str(self.name)
应该适合你。
答案 1 :(得分:1)
def __unicode__(self): # Python 3: def __str__(self):
return str(self.name)