Code

Ticket #7888: 7888.diff

File 7888.diff, 821 bytes (added by Erwin, 6 years ago)
Line 
1Index: django/forms/models.py
2===================================================================
3--- django/forms/models.py      (revision 8330)
4+++ django/forms/models.py      (working copy)
5@@ -320,6 +320,10 @@
6         if self.model._meta.has_auto_field:
7             self._pk_field_name = self.model._meta.pk.attname
8             form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput)
9+        elif len(self.model._meta.parents) == 1:
10+            self._pk_field_name = self.model._meta.pk.attname
11+            form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput,
12+                initial=self.instance.pk)
13         super(BaseModelFormSet, self).add_fields(form, index)
14 
15 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),