Ticket #7938: 7938_custom_primary_key_formset_fix.1.diff

File 7938_custom_primary_key_formset_fix.1.diff, 824 bytes (added by Brian Rosner, 16 years ago)
  • django/forms/models.py

     
    378378
    379379    def add_fields(self, form, index):
    380380        """Add a hidden field for the object's primary key."""
    381         self._pk_field_name = self.model._meta.pk.attname
    382         form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput)
     381        if self.model._meta.has_auto_field:
     382            self._pk_field_name = self.model._meta.pk.attname
     383            form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput)
    383384        super(BaseModelFormSet, self).add_fields(form, index)
    384385
    385386def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
Back to Top