Code

Ticket #17988: model_formset_check_commit_before_delete.diff

File model_formset_check_commit_before_delete.diff, 598 bytes (added by rem, 2 years ago)

Check commit=True before deleting existing objects.

Line 
1Index: django/forms/models.py
2===================================================================
3--- django/forms/models.py      (revision 17811)
4+++ django/forms/models.py      (working copy)
5@@ -607,7 +607,8 @@
6             obj = self._existing_object(pk_value)
7             if self.can_delete and self._should_delete_form(form):
8                 self.deleted_objects.append(obj)
9-                obj.delete()
10+                if commit:
11+                    obj.delete()
12                 continue
13             if form.has_changed():
14                 self.changed_objects.append((obj, form.changed_data))