From 8aab03ab5550d8da9268eb384bfc7092dd4fab0a Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 2 Aug 2022 09:34:18 +0200 Subject: [PATCH] [4.1.x] Fixed #33876, Refs #32229 -- Made management forms render with div.html template. Thanks to Claude Paroz for the report. Backport of 89e695a69b16b8c0e720169b3ca4852cfd0c485f from main --- django/forms/formsets.py | 2 ++ tests/forms_tests/tests/test_formsets.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 3adbc6979a..57676428ff 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -32,6 +32,8 @@ class ManagementForm(Form): as well. """ + template_name = "django/forms/div.html" # RemovedInDjango50Warning. + TOTAL_FORMS = IntegerField(widget=HiddenInput) INITIAL_FORMS = IntegerField(widget=HiddenInput) # MIN_NUM_FORM_COUNT and MAX_NUM_FORM_COUNT are output with the rest of the diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 96a2189d70..c36a79d4e0 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -1910,3 +1910,14 @@ class DeprecationTests(SimpleTestCase): ChoiceFormSet = formset_factory(Choice) formset = ChoiceFormSet() str(formset) + + def test_no_management_form_warning(self): + """ + Management forms are already rendered with the new div template. + """ + with isolate_lru_cache(get_default_renderer), self.settings( + FORM_RENDERER="django.forms.renderers.DjangoTemplates" + ): + ChoiceFormSet = formset_factory(Choice, formset=BaseFormSet) + formset = ChoiceFormSet() + str(formset.management_form)