Skip to content

Commit

Permalink
Fixed #35913 -- Prevented formset name suffix 'FormFormSet'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoliny0919 authored and sarahboyce committed Nov 20, 2024
1 parent 4c452cc commit f60d5e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django/forms/formsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,12 @@ def formset_factory(
"validate_max": validate_max,
"renderer": renderer,
}
return type(form.__name__ + "FormSet", (formset,), attrs)
form_name = form.__name__
if form_name.endswith("Form"):
formset_name = form_name + "Set"
else:
formset_name = form_name + "FormSet"
return type(formset_name, (formset,), attrs)


def all_valid(formsets):
Expand Down
6 changes: 6 additions & 0 deletions tests/forms_tests/tests/test_formsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def test_basic_formset(self):
self.assertFalse(formset.is_valid())
self.assertFalse(formset.has_changed())

def test_formset_name(self):
ArticleFormSet = formset_factory(ArticleForm)
ChoiceFormSet = formset_factory(Choice)
self.assertEqual(ArticleFormSet.__name__, "ArticleFormSet")
self.assertEqual(ChoiceFormSet.__name__, "ChoiceFormSet")

def test_form_kwargs_formset(self):
"""
Custom kwargs set on the formset instance are passed to the
Expand Down

0 comments on commit f60d5e4

Please sign in to comment.