#8477: OneToOneField being ignored in Django Admin
----------------------------------------------+-----------------------------
Reporter: [EMAIL PROTECTED] | Owner: nobody
Status: new | Milestone: 1.0
Component: Admin interface | Version: 1.0-beta-1
Resolution: | Keywords: onetoonefield
Stage: Unreviewed | Has_patch: 0
Needs_docs: | Needs_tests:
Needs_better_patch: |
----------------------------------------------+-----------------------------
Changes (by julianb):
* needs_better_patch: =>
* needs_tests: =>
* needs_docs: =>
Old description:
> 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.
New description:
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.
Comment:
Made description readable.
--
Ticket URL: <http://code.djangoproject.com/ticket/8477#comment:>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---