#7888: BaseModelFormSet cannot resolve instances of inherited models when saving ---------------------------------------+------------------------------------ Reporter: bpeschier | Owner: nobody Status: new | Milestone: Component: django.newforms | Version: SVN Keywords: modelformset, inheritance | Stage: Unreviewed Has_patch: 0 | ---------------------------------------+------------------------------------ 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 :-) -- Ticket URL: <http://code.djangoproject.com/ticket/7888> 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 -~----------~----~----~----~------~----~------~--~---
