Opened 14 years ago

Closed 14 years ago

Last modified 11 years ago

#8477 closed (fixed)

OneToOneField being ignored in Django Admin

Reported by: andrew_rust@… Owned by: nobody
Component: contrib.admin Version: 1.0-beta
Severity: Keywords: onetoonefield
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

I have the following models set up:

from django.db import models
import datetime

class Ref(models.Model):
    ref = models.CharField(max_length=200)

    def __unicode__(self):
        return self.ref

class Poll(models.Model):
    ref = models.OneToOneField(Ref, verbose_name='reference')
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    def __unicode__(self):
        return self.ref

    def __unicode__(self):
        return self.question

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)

    def __unicode__(self):
        return self.choice

class Vote(models.Model):
    site = models.CharField(max_length=200)
    choice = models.ForeignKey(Choice)
    votes = models.IntegerField()
    date = models.DateTimeField('date voted')

    def __unicode__(self):

from django.contrib import admin

class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 5

class PollAdmin(admin.ModelAdmin):
    fieldsets = [
        ('Poll Information', {
                'fields': ('ref', 'question')
        ('Date information', {
                'fields': ['pub_date']
    inlines = [ChoiceInline]
    list_display = ('question', 'ref', 'pub_date')
    list_display_links = ('question', 'ref')
    list_per_page = 25
    search_fields = ['question']
    save_on_top = True, PollAdmin)

When trying to run syncdb against this i get the following error....

Traceback (most recent call last):
  File "C:\NTTSites\django\bin\", line 5, in <module>
  File "C:\NTTSites\django\core\management\", line 325, in execute_fr
  File "C:\NTTSites\django\core\management\", line 295, in execute
  File "C:\NTTSites\django\core\management\", line 77, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\NTTSites\django\core\management\", line 95, in execute
  File "C:\NTTSites\django\core\management\", line 122, in validate
    num_errors = get_validation_errors(s, app)
  File "C:\NTTSites\django\core\management\", line 28, in get_valid
    for (app_name, error) in get_app_errors().items():
  File "C:\NTTSites\django\db\models\", line 128, in get_app_errors
  File "C:\NTTSites\django\db\models\", line 57, in _populate
    self.load_app(app_name, True)
  File "C:\NTTSites\django\db\models\", line 72, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
  File "C:\NTTSites\sites\xen\lib\xen\django\apps\poll\", line 59, in <
module>, PollAdmin)
  File "C:\NTTSites\django\contrib\admin\", line 90, in register
    validate(admin_class, model)
  File "C:\NTTSites\django\contrib\admin\", line 19, in validate
    _validate_base(cls, model)
  File "C:\NTTSites\django\contrib\admin\", line 201, in _validate_
    _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field)
  File "C:\NTTSites\django\contrib\admin\", line 162, in _check_for
    return _check_form_field_exists(cls, model, opts, label, field)
  File "C:\NTTSites\django\contrib\admin\", line 287, in _check_for
    "is missing from the form." % (cls.__name__, label, field))
django.core.exceptions.ImproperlyConfigured: `PollAdmin.fieldsets[1][1]['fields'
]` refers to field `ref` that is missing from the form.

If i change the OneToOneField to a ForeignKeyField then syncdb runs with no problems.

Change History (4)

comment:1 Changed 14 years ago by Julian Bez

Description: modified (diff)

Made description readable.

comment:2 Changed 14 years ago by Malcolm Tredinnick

Description: modified (diff)

Is this fixed/changed in way by [8469]?

comment:3 Changed 14 years ago by Ivan Giuliani

Resolution: fixed
Status: newclosed

I tried to reproduce the problem and it works after [8469] but not before, so I guess it has fixed this too.

comment:4 Changed 11 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top