0

I'm trying to make a poll with Django but I'm very new to it and when I go to the admin thing it gives this error:

ImproperlyConfigured at /admin/polls/poll/1/
'PollAdmin.fields' refers to field 'None' that is missing from the form.

I'm not very sure what that means but this is my admin.py file which I think is causing the error:

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)

Edit:

Here's my models file if that matters:

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

Edit (again)

Now I fixed my PollAdmin class to this:

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

But it's saying:

DoesNotExist at /admin/polls/poll/1/
Site matching query does not exist.
Addison
  • 3,791
  • 3
  • 28
  • 48

1 Answers1

4

Use fieldsets instead of fields:

class PollAdmin(admin.ModelAdmin):
  fieldsets = [
    (None,         {'fields': ['question']}),
    ('Date information', {'fields': ['pub_date']}),
Calvin Jia
  • 856
  • 5
  • 5
  • Now it says this: 'PollAdmin.fieldsets[1][1]['fields']' refers to field 'pub date' that is missing from the form. – Addison Aug 01 '12 at 00:19
  • Oops sorry you need an underscore between pub and date – Calvin Jia Aug 01 '12 at 00:20
  • Did you run python manage.py syncdb after adding the admin app? – Calvin Jia Aug 01 '12 at 00:22
  • Nope. I just did and it says this. Site matching query does not exist. Sorry I'm really new to this – Addison Aug 01 '12 at 00:25
  • Sorry I haven't encountered this kind of error before, but there are many posts on stack overflow regarding this: http://stackoverflow.com/questions/2674615/django-cms-malfunction-site-matching-query-does-not-exist – Calvin Jia Aug 01 '12 at 00:30