Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#10799 closed (fixed)

List editable breaks with model inheritance and parent_link=True

Reported by: Will Hardy Owned by: Alex Gaynor
Component: contrib.admin Version: master
Severity: Keywords: list_editable parent_link inheritance
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Similar symptoms to #10622, the admin site raises an exception where the model explicity defines a parent_link and list_editable is set in the model's admin.

I have attached a regression test that shows this in action.

Attachments (2)

list_editable_and_parent_link.diff (2.3 KB) - added by Will Hardy 9 years ago.
Regression test showing this bug in action
list-editable.diff (6.5 KB) - added by Alex Gaynor 9 years ago.

Download all attachments as: .zip

Change History (9)

Changed 9 years ago by Will Hardy

Regression test showing this bug in action

comment:1 Changed 9 years ago by Will Hardy

A couple of extra bits of potentially useful information:

  1. exception appears whether or not parent_link is set as a primary_key.
  1. looking at line 950 of django/contrib/admin/
        elif self.list_editable:
            FormSet = self.get_changelist_formset(request)
            formset = cl.formset = FormSet(queryset=cl.result_list)

The FormSet here looks ok (parent_link and non-parent_link version appear to be the same), but each of the forms in formset.forms is missing the field for the primary key. The result_list is of course the same with or without parent_link.

I find this strange because it appears to use the (no doubt well-tested) generic factory functions from forms.models.

I don't know the internal django code well enough to give a useful opinion here, but this is what I was able to observe.

comment:2 Changed 9 years ago by Alex Gaynor

Owner: changed from nobody to Alex Gaynor
Triage Stage: UnreviewedAccepted

Assigning to me.

Changed 9 years ago by Alex Gaynor

Attachment: list-editable.diff added

comment:3 Changed 9 years ago by Alex Gaynor

Has patch: set

comment:4 Changed 9 years ago by Will Hardy

I probably should have given my regression test a more descriptive title and a docstring, eg:

    def test_inheritance_parent_link(self):
        " Ensure that the admin list_editable view works for models with parent_link. "

comment:5 Changed 9 years ago by Jacob

Triage Stage: AcceptedReady for checkin

comment:6 Changed 9 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [10590]) Fixed #10799: fixed the use of list_editable with model inheritance and custom one-to-one parent links. Thanks, Alex Gaynor.

comment:7 Changed 7 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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