summaryrefslogtreecommitdiff
path: root/django/forms/models.py
diff options
context:
space:
mode:
authorJason Hoos <jhoos@maestrohealth.com>2015-06-05 15:04:24 -0500
committerTim Graham <timograham@gmail.com>2015-06-26 09:15:59 -0400
commit429680146304c44e92ecff655280bc464121f769 (patch)
tree6d341529e1d545f8b5d5c994b72a3fbdc7afa27c /django/forms/models.py
parenta97e50c5e6afe0ce2a8fb2ca27c88e57611b0053 (diff)
[1.8.x] Fixed #24958 -- Fixed inline forms using UUID-PK parents with auto-PK children.
Backport of a50b66da30320887c23c73927f6b2ab41e0301bf from master
Diffstat (limited to 'django/forms/models.py')
-rw-r--r--django/forms/models.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index b8345d8856..08a3697cc1 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -922,10 +922,15 @@ class BaseInlineFormSet(BaseModelFormSet):
if self.fk.rel.field_name != self.fk.rel.to._meta.pk.name:
kwargs['to_field'] = self.fk.rel.field_name
- # If we're adding a new object, ignore a parent's auto-generated pk
+ # If we're adding a new object, ignore a parent's auto-generated key
# as it will be regenerated on the save request.
- if self.instance._state.adding and form._meta.model._meta.pk.has_default():
- self.instance.pk = None
+ if self.instance._state.adding:
+ if kwargs.get('to_field') is not None:
+ to_field = self.instance._meta.get_field(kwargs['to_field'])
+ else:
+ to_field = self.instance._meta.pk
+ if to_field.has_default():
+ setattr(self.instance, to_field.attname, None)
form.fields[name] = InlineForeignKeyField(self.instance, **kwargs)