1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.8.x] Fixed #24395 -- Ensured inline ModelsForms have an updated related instance.

Backport of 4c2f546b55 from master
This commit is contained in:
Stanislas Guerra
2015-02-24 10:54:05 +01:00
committed by Tim Graham
parent 450b42eafe
commit a3fca05b05
2 changed files with 36 additions and 0 deletions

View File

@@ -891,6 +891,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)