我正在尝试使用Django进行投票,但我对它很新,当我转到管理员时它会出现此错误:
ImproperlyConfigured at /admin/polls/poll/1/
'PollAdmin.fields' refers to field 'None' that is missing from the form.
我不太确定这意味着什么,但这是我的admin.py文件,我认为这会导致错误:
from django.contrib import admin
from polls.models import Poll
class PollAdmin(admin.ModelAdmin):
fields = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub date']}),
admin.site.register(Poll, PollAdmin)
修改:
如果重要的话,这是我的模型文件:
from django.db import models
import datetime
from django.utils import timezone
class Poll(models.Model):
question = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days = 1)
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length = 200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice_text
编辑(再次)
现在我修改了我的PollAdmin类:
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub_date']}),
]
但是它说:
DoesNotExist at /admin/polls/poll/1/
Site matching query does not exist.
答案 0 :(得分:4)
使用字段集代替字段:
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub_date']}),