Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#9863 closed (fixed)

InlineModelAdmin breaks in the latest revision 9650

Reported by: shilin Owned by: Keith Bussell
Component: Forms Version: dev
Severity: Keywords: admin
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've defined two models like this:

class Parent(models.Model):    
    name = models.CharField(max_length = 128, db_index = True)    

class Child(models.Model):    
    parent = models.ForeignKey(Parent, related_name = 'child_set', editable = False)
    name = models.CharField(max_length = 30, blank = True)    

And in admin.py, I tried to edit the Child object related to the certain Parent object.

class ChildInline(admin.StackedInline):
    model = Child
    extra = 10

class ParentAdmin(admin.ModelAdmin):    
    inlines = [
       ChildInline,     
    ]

site.register(Parent, ParentAdmin)

However, the admin application shows something like below:

KeyError at /admin/object/object/add/

'object'

The line of code which throws the exception is

C:\Python24\lib\site-packages\django\forms\models.py in add_fields

 487. return save_instance(form, new_obj, exclude=[self._pk_field.name], commit=commit)
 488.
 489. def add_fields(self, form, index):
 490. super(BaseInlineFormSet, self).add_fields(form, index)
 491. if self._pk_field == self.fk:
 492. form.fields[self._pk_field.name] = InlineForeignKeyField(self.instance, pk_field=True)
 493. else:

 >>>This Line>>> 494. form.fields[self.fk.name] = InlineForeignKeyField(self.instance, label=form.fields[self.fk.name].label) ...

I've tried to revert my Django to revision 9160, the same model and admin settings do not throw the same exception. It's like that the foreignkey field leads to this error.
But I'm quite confused about it.

Attachments (3)

test_9863.diff (3.6 KB ) - added by Keith Bussell 15 years ago.
Stand-alone django test case exhibiting the problem
9683.diff (3.0 KB ) - added by Alex Gaynor 15 years ago.
9683.2.diff (3.1 KB ) - added by Alex Gaynor 15 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by shilin, 15 years ago

My mistake
The error should be

KeyError at /admin/object/object/add/

'parent'

comment:2 by django_banjo, 15 years ago

Component: django.contrib.adminForms

This error also happens with inlineformset_factory() if a model's field has editable=False or if it's used with formset = MyFormSet(... exclude=('some_field')).

comment:3 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:4 by Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:5 by Keith Bussell, 15 years ago

Owner: changed from nobody to Keith Bussell
Status: newassigned

comment:6 by Keith Bussell, 15 years ago

Note to self: something broke in r9297

by Keith Bussell, 15 years ago

Attachment: test_9863.diff added

Stand-alone django test case exhibiting the problem

by Alex Gaynor, 15 years ago

Attachment: 9683.diff added

comment:7 by Alex Gaynor, 15 years ago

Has patch: set

by Alex Gaynor, 15 years ago

Attachment: 9683.2.diff added

comment:8 by jkocherhans, 15 years ago

Resolution: fixed
Status: assignedclosed

(In [10239]) Fixed #9863. A ForeignKey with editable=False to the parent in an inline no longer raises an exception. Thanks to keithb for the test case and Alex Gaynor for the patch.

comment:9 by jkocherhans, 15 years ago

(In [10287]) [1.0.X] Fixed #9863. A ForeignKey with editable=False to the parent in an inline no longer raises an exception. Thanks to keithb for the test case and Alex Gaynor for the patch. Backport of r10239 from trunk.

comment:10 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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