2012-08-01 42 views
0

我試圖用Django做一個民意調查,但我很新,當我去管理的事情,它給這個錯誤:'PollAdmin.fields'是指字段'無',從表格中缺少

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. 

回答

4

使用fieldsets而不是字段:

class PollAdmin(admin.ModelAdmin): 
    fieldsets = [ 
    (None,   {'fields': ['question']}), 
    ('Date information', {'fields': ['pub_date']}), 
+0

現在它說:'PollAdmin.fieldsets [1] [1] ['fields']'指的是表單中缺少的'pub date'字段。 – Addison 2012-08-01 00:19:15

+0

抱歉,您需要酒吧和日期之間的下劃線 – 2012-08-01 00:20:10

+0

謝謝!但它現在說...沒有這樣的表格:django_session。抱歉... – Addison 2012-08-01 00:21:56