Code

Ticket #18751: ticket-18751.0.diff

File ticket-18751.0.diff, 981 bytes (added by charettes, 2 years ago)
Line 
1diff --git a/django/forms/formsets.py b/django/forms/formsets.py
2index 4ea8dc4..058a086 100644
3--- a/django/forms/formsets.py
4+++ b/django/forms/formsets.py
5@@ -252,13 +252,13 @@ class BaseFormSet(StrAndUnicode):
6     errors = property(_get_errors)
7 
8     def _should_delete_form(self, form):
9-        # The way we lookup the value of the deletion field here takes
10-        # more code than we'd like, but the form's cleaned_data will
11-        # not exist if the form is invalid.
12-        field = form.fields[DELETION_FIELD_NAME]
13-        raw_value = form._raw_value(DELETION_FIELD_NAME)
14-        should_delete = field.clean(raw_value)
15-        return should_delete
16+        """
17+        Returns wether or not the form was marked for deletion
18+        """
19+        # Make sure to trigger form validation in order to populate
20+        # cleaned data.
21+        form.is_valid()
22+        return form.cleaned_data.get(DELETION_FIELD_NAME, False)
23 
24     def is_valid(self):
25         """