1
0
mirror of https://github.com/django/django.git synced 2025-10-25 06:36:07 +00:00

Fixed #24958 -- Fixed inline forms using UUID-PK parents with auto-PK children.

This commit is contained in:
Jason Hoos
2015-06-05 15:04:24 -05:00
committed by Tim Graham
parent 0cc39e50e1
commit a50b66da30
4 changed files with 89 additions and 4 deletions

View File

@@ -929,10 +929,15 @@ class BaseInlineFormSet(BaseModelFormSet):
if self.fk.remote_field.field_name != self.fk.remote_field.model._meta.pk.name:
kwargs['to_field'] = self.fk.remote_field.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)