diff options
| author | Neeraj Kumar <sainineeraj1234@gmail.com> | 2023-06-07 01:27:32 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-07-07 09:11:46 +0200 |
| commit | eed096574fea5c9d82d0dc5952ad439dfde13718 (patch) | |
| tree | e61a70657c124e06da5a71c0dca6f648aa04c3e4 /django/forms/models.py | |
| parent | b91d62cca07638741f5902713983f71478589b0e (diff) | |
Fixed #32210 -- Fixed model inlines with to_field that has a default.
Diffstat (limited to 'django/forms/models.py')
| -rw-r--r-- | django/forms/models.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 3fa04b821f..dc30d79b5d 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -1177,7 +1177,13 @@ class BaseInlineFormSet(BaseModelFormSet): to_field = self.instance._meta.get_field(kwargs["to_field"]) else: to_field = self.instance._meta.pk - if to_field.has_default(): + + if to_field.has_default() and ( + # Don't ignore a parent's auto-generated key if it's not the + # parent model's pk and form data is provided. + to_field.attname == self.fk.remote_field.model._meta.pk.name + or not form.data + ): setattr(self.instance, to_field.attname, None) form.fields[name] = InlineForeignKeyField(self.instance, **kwargs) |
