Opened 16 years ago

Closed 16 years ago

Last modified 13 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):
        return self.site

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

admin.site.register(Poll, PollAdmin)

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


Traceback (most recent call last):
  File "C:\NTTSites\django\bin\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\NTTSites\django\core\management\__init__.py", line 325, in execute_fr
om_command_line
    utility.execute()
  File "C:\NTTSites\django\core\management\__init__.py", line 295, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\NTTSites\django\core\management\base.py", line 77, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\NTTSites\django\core\management\base.py", line 95, in execute
    self.validate()
  File "C:\NTTSites\django\core\management\base.py", line 122, in validate
    num_errors = get_validation_errors(s, app)
  File "C:\NTTSites\django\core\management\validation.py", line 28, in get_valid
ation_errors
    for (app_name, error) in get_app_errors().items():
  File "C:\NTTSites\django\db\models\loading.py", line 128, in get_app_errors
    self._populate()
  File "C:\NTTSites\django\db\models\loading.py", line 57, in _populate
    self.load_app(app_name, True)
  File "C:\NTTSites\django\db\models\loading.py", line 72, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
  File "C:\NTTSites\sites\xen\lib\xen\django\apps\poll\models.py", line 59, in <
module>
    admin.site.register(Poll, PollAdmin)
  File "C:\NTTSites\django\contrib\admin\sites.py", line 90, in register
    validate(admin_class, model)
  File "C:\NTTSites\django\contrib\admin\validation.py", line 19, in validate
    _validate_base(cls, model)
  File "C:\NTTSites\django\contrib\admin\validation.py", line 201, in _validate_
base
    _check_form_field_existsw("fieldsets[%d][1]['fields']" % idx, field)
  File "C:\NTTSites\django\contrib\admin\validation.py", line 162, in _check_for
m_field_existsw
    return _check_form_field_exists(cls, model, opts, label, field)
  File "C:\NTTSites\django\contrib\admin\validation.py", line 287, in _check_for
m_field_exists
    "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 by Julian Bez, 16 years ago

Description: modified (diff)

Made description readable.

comment:2 by Malcolm Tredinnick, 16 years ago

Description: modified (diff)

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

comment:3 by Ivan Giuliani, 16 years ago

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 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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