4

unicode (self) 不适合我。我仍然可以在管理员中看到“名称对象”。我的代码如下:

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

感谢您

4

2 回答 2

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)

应该为你工作。

于 2013-05-07T06:15:35.727 回答
1

Python INDENTION 将负责大部分时间,正确工作,使用编辑器或 使用选项卡分离出_ unicode _(self)

      def __unicode__(self):  # Python 3: def __str__(self):
            return str(self.name)
于 2013-05-07T06:19:25.870 回答