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

Fixed #24395 -- Ensured inline ModelsForms have an updated related instance.

This commit is contained in:
Stanislas Guerra
2015-02-24 10:54:05 +01:00
committed by Tim Graham
parent 8e129b42ad
commit 4c2f546b55
2 changed files with 36 additions and 0 deletions

View File

@@ -904,6 +904,10 @@ class BaseInlineFormSet(BaseModelFormSet):
return cls.fk.rel.get_accessor_name(model=cls.model).replace('+', '')
def save_new(self, form, commit=True):
# Ensure the latest copy of the related instance is present on each
# form (it may have been saved after the formset was originally
# instantiated).
setattr(form.instance, self.fk.name, self.instance)
# Use commit=False so we can assign the parent key afterwards, then
# save the object.
obj = form.save(commit=False)