我是Django和Stuck的新手,但遇到了一些幼稚的错误。我将项目名称命名为“ singup”,并在模型中添加了“ smart_unicode实用程序”,但不幸的是,在我的管理站点中,我没有看到任何更改。我想将每个存储的注册称为电子邮件。
这是我的models.py文件:
from django.db import models
from django.utils.encoding import smart_unicode
# Create your models here.
class signup(models.Model):
first_name=models.CharField(max_length=12,null=False,blank=False)
last_name=models.CharField(max_length=12,null=False,blank=False)
email=models.EmailField(max_length=60,null=False,blank=False)
timestamp=models.DateTimeField(auto_now_add=True,auto_now=False)
updated=models.DateTimeField(auto_now_add=False,auto_now=True)
def __unicode__(self):
return smart_unicode(self.email)
这是我的admin.py
from django.contrib import admin
# Register your models here.
from models import signup
class signupAdmin(admin.ModelAdmin):
class Meta:
model=signup
admin.site.register(signup,signupAdmin)
这是我的管理网站图片。
方法的名称应为__unicode__
。有双下划线,而不是单下划线。
def __unicode__(self):
return smart_unicode(self.email)
对于python 2
def __str__(self):
return smart_unicode(self.email)
所以完整的代码应该是
class signup(models.Model):
first_name=models.CharField(max_length=12,null=False,blank=False)
last_name=models.CharField(max_length=12,null=False,blank=False)
email=models.EmailField(max_length=60,null=False,blank=False)
timestamp=models.DateTimeField(auto_now_add=True,auto_now=False)
updated=models.DateTimeField(auto_now_add=False,auto_now=True)
def __str__(self):
return smart_unicode(self.email)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句