在这里的教程中,我开始运行 was_published_recently 并收到此错误:
在 /admin/polls/poll/PollAdmin.list_display[2] 中配置不当,“was_published_recently”不是“PollAdmin”的可调用或属性,也不是在“Poll”模型中找到的。请求方法:GET 请求 URL:/admin/polls/poll/ Django 版本:1.4 异常类型:ImproperlyConfigured 异常值:
PollAdmin.list_display[2],“was_published_recently”不是“PollAdmin”的可调用或属性,也不是在模型“民意调查”。异常位置:C:\Python27\lib\site-packages\django\contrib\admin\validation.py 在验证中,第 38 行
这是我的代码:
from polls.models import Poll
from django.contrib import admin
from polls.models import Choice
class ChoiceInline(admin.TabularInline):
model = Choice
extra = 3
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
]
inlines = [ChoiceInline]
class PollAdmin(admin.ModelAdmin):
# ...
list_display = ('question', 'pub_date', 'was_published_recently')
admin.site.register(Poll, PollAdmin)
这是我的投票模型
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
class Poll(models.Model):
# ...
def __unicode__(self):
return self.question
class Choice(models.Model):
# ...
def __unicode__(self):
return self.choice