summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorTies Jan Hefting <hello@tiesjan.com>2021-08-03 12:27:22 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-08-03 13:12:50 +0200
commit4f3acf957918843b4c40ff2edfb929bcfaa3730e (patch)
tree18fd457c502af86c06ec5102a6cc42edc18195a0 /django/forms
parent47cb85b542470e1712b5d71b0d3d0ec8c7b0dbdc (diff)
Fixed #32984 -- Allowed customizing a deletion field widget in formsets.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/formsets.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index b8e0d62fd9..25f8378354 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -2,7 +2,7 @@ from django.core.exceptions import ValidationError
from django.forms import Form
from django.forms.fields import BooleanField, IntegerField
from django.forms.utils import ErrorList
-from django.forms.widgets import HiddenInput, NumberInput
+from django.forms.widgets import CheckboxInput, HiddenInput, NumberInput
from django.utils.functional import cached_property
from django.utils.html import html_safe
from django.utils.safestring import mark_safe
@@ -55,6 +55,7 @@ class BaseFormSet:
"""
A collection of instances of the same Form class.
"""
+ deletion_widget = CheckboxInput
ordering_widget = NumberInput
default_error_messages = {
'missing_management_form': _(
@@ -284,6 +285,10 @@ class BaseFormSet:
return 'form'
@classmethod
+ def get_deletion_widget(cls):
+ return cls.deletion_widget
+
+ @classmethod
def get_ordering_widget(cls):
return cls.ordering_widget
@@ -417,7 +422,11 @@ class BaseFormSet:
widget=self.get_ordering_widget(),
)
if self.can_delete and (self.can_delete_extra or index < initial_form_count):
- form.fields[DELETION_FIELD_NAME] = BooleanField(label=_('Delete'), required=False)
+ form.fields[DELETION_FIELD_NAME] = BooleanField(
+ label=_('Delete'),
+ required=False,
+ widget=self.get_deletion_widget(),
+ )
def add_prefix(self, index):
return '%s-%s' % (self.prefix, index)