﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7888	BaseModelFormSet cannot resolve instances of inherited models when saving	Bas Peschier	Brian Rosner	"When you create a !BaseModelFormSet for a Model which inherits from a user-defined Model, the save operation fails with a !KeyError (key is None). This is because the primary key's attribute name is not what it expects it to be. As far as i can see the following is supposed to take place:

 * creates a !BaseModelFormSet, loads initials from model_to_dict for all forms from a !QuerySet, including the 'id'-field
 * !ModelFormSet adds a hidden field via add_fields named pk.attname to each form which will contain the primary key. In normal (most?) cases, this attname is 'id'
 * The form uses initial data when cleaning, outputing the pk nicely in the hidden field.
 * When saving, use the hidden field to retrieve the object it refers to and save it.

The fact that the attributename of a pk for an inherited model is ""<parentmodel>_ptr_id"" screws things up. This can be fixed in three ways:
 
 * Patch model_to_dict to include the actual pk.attrname: pk key/value-pair or...
 * Setup the hiddenfield in add_fields of !BaseModelFormSet to include a initial value
 * Some clever way I did not think of yet.

I really love these formsets, they reduce coding time with large factors instead of reducing it by a few minutes :-)"		closed	Forms	dev		fixed	modelformset, inheritance	ville@…	Accepted	1	0	0	1	0	0
