Kind of duplicate of both of these:
- How to force-save an "empty"/unchanged django admin inline?
- How to force creation of unchanged django admin inline object in django 1.9
But I am still wondering is there any better way to do it in any later Django updates?
I aimed to modify my model admin stacked inline objects (pre or post save doesn't matter) when parent model admin instance is changed. I tried overriding save_formset
and save_related
in model admin class as written in Django docs here and here using commit=False
. For example:
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
for instance in instances:
instance.any_field = "value"
instance.save()
The method formset.save(commit=False)
returns inline form instances only if they are changed on Django Admin panel as mentioned in django docs, but it doesn't return list of inline objects if they are not changed, even after sending commit=False
. I need to edit those inline objects regardless if they were changed on admin panel or not.