1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Ensure that custom primary keys are always shown on a formset. Refs #7938. Thanks magneto for discovering this problem.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8179 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner
2008-08-01 20:35:40 +00:00
parent 61b335700c
commit af35fb1fbb
2 changed files with 17 additions and 2 deletions

View File

@@ -378,8 +378,9 @@ class BaseModelFormSet(BaseFormSet):
def add_fields(self, form, index):
"""Add a hidden field for the object's primary key."""
self._pk_field_name = self.model._meta.pk.attname
form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput)
if self.model._meta.has_auto_field:
self._pk_field_name = self.model._meta.pk.attname
form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput)
super(BaseModelFormSet, self).add_fields(form, index)
def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),