Ticket #13794: to_field_formsets.2.patch

File to_field_formsets.2.patch, 741 bytes (added by anonymous, 11 years ago)
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index a849436..6419fcb 100644
    a b class BaseInlineFormSet(BaseModelFormSet):  
    859859            form.data[form.add_prefix(self.fk.name)] = None
    860860
    861861        # Set the fk value here so that the form can do its validation.
    862         setattr(form.instance, self.fk.get_attname(), self.instance.pk)
     862        fk_value = self.instance.pk
     863        if self.fk.rel.field_name != self.fk.rel.to._meta.pk.name:
     864            fk_value = getattr(self.instance, self.fk.rel.field_name)
     865            fk_value = getattr(fk_value, 'pk', fk_value)
     866        setattr(form.instance, self.fk.get_attname(), fk_value)
    863867        return form
Back to Top