[Django] #35913: About the FormSet class name generated through the formset_factory.

32 views
Skip to first unread message

Django

unread,
Nov 16, 2024, 2:19:37 AM11/16/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Type:
| Cleanup/optimization
Status: new | Component: Forms
Version: 5.1 | Severity: Normal
Keywords: FormSet, | Triage Stage:
formset_factory | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
When you define Django Form, what format do you usually name it?
In my case, I usually name it "xxxForm".
The names of the forms used as examples in official documents related to
Django Form are the same as my name define format.
{{{
# Working with forms docs.
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField(widget=forms.Textarea)
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)

# Working with forms docs.
class ArticleForm(forms.Form):
title = forms.CharField()
pub_date = forms.DateField()

# FormField docs.
class CommentForm(forms.Form):
name = forms.CharField()
url = forms.URLField()
comment = forms.CharField()
}}}
The way django people name it may be based on the developers' tendencies
or tastes, but I think most of them are built in the format as xxxForm.
The FormSet class I created by passing xxxForm name format to the
formset_factory is named as follows.
{{{
>>> ArticleFormSet = formset_factory(ArticleForm)
>>> ArticleFormSet.__name__
'ArticleFormFormSet'
}}}
The name of the FormSet class created through the formset_factory in the
form xxxForm name format is a little strange.
This is because when formset_factory creates a class through type, it adds
a static "FormSet" to the form name.
{{{
def formset_factory(
form,
formset=BaseFormSet,
extra=1,
can_order=False,
can_delete=False,
max_num=None,
validate_max=False,
min_num=None,
validate_min=False,
absolute_max=None,
can_delete_extra=True,
renderer=None,
):
...
return type(form.__name__ + "FormSet", (formset,), attrs)
}}}
I wonder if the format of these names is intended :)
--
Ticket URL: <https://code.djangoproject.com/ticket/35913>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 16, 2024, 2:19:52 AM11/16/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage:
formset_factory | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* owner: (none) => Antoliny
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:1>

Django

unread,
Nov 16, 2024, 7:48:29 PM11/16/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage:
formset_factory | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):

I agree this is a bit odd.
[https://github.com/django/django/blob/2debd018dbc7aba0b98b4c082bbb1fa1d195a47e/tests/forms_tests/tests/test_formsets.py#L1632-L1636
The test] for the `Formset.__repr__()` uses a form called `Choice` so the
result is `ChoiceFormSet` as expected.

As you pointed out, perhaps to match the documented convention of ending
all form names with "Form" we could consider appending "Set" rather than
"FormSet" if `form.__name__` ends with `Form`. I can't think of any way
this would break backward compatibility, and it might make debugging a
little less confusing.
--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:2>

Django

unread,
Nov 16, 2024, 8:45:09 PM11/16/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage:
formset_factory | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Antoliny):

Thank you for your good opinion @Tim Graham !
It was not found because we tested it through `Choice` in the test.
I agree to change "FormSet" to "Set".
--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:3>

Django

unread,
Nov 16, 2024, 9:32:50 PM11/16/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage:
formset_factory | Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* has_patch: 0 => 1
* needs_docs: 0 => 1
* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:4>

Django

unread,
Nov 16, 2024, 9:34:51 PM11/16/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage:
formset_factory | Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Antoliny):

[https://github.com/django/django/pull/18820 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:5>

Django

unread,
Nov 16, 2024, 10:08:30 PM11/16/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage:
formset_factory | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* needs_docs: 1 => 0
* needs_tests: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:6>

Django

unread,
Nov 18, 2024, 4:05:08 AM11/18/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage: Accepted
formset_factory |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:7>

Django

unread,
Nov 19, 2024, 4:23:36 AM11/19/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage: Accepted
formset_factory |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:8>

Django

unread,
Nov 19, 2024, 7:26:35 PM11/19/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage: Accepted
formset_factory |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:9>

Django

unread,
Nov 20, 2024, 4:11:39 AM11/20/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution:
Keywords: FormSet, | Triage Stage: Ready for
formset_factory | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:10>

Django

unread,
Nov 20, 2024, 5:36:43 AM11/20/24
to django-...@googlegroups.com
#35913: About the FormSet class name generated through the formset_factory.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: closed
Cleanup/optimization |
Component: Forms | Version: 5.1
Severity: Normal | Resolution: fixed
Keywords: FormSet, | Triage Stage: Ready for
formset_factory | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"f60d5e46e131b94d6ecc92b6891689ccc94bd1c9" f60d5e46]:
{{{#!CommitTicketReference repository=""
revision="f60d5e46e131b94d6ecc92b6891689ccc94bd1c9"
Fixed #35913 -- Prevented formset name suffix 'FormFormSet'.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35913#comment:11>
Reply all
Reply to author
Forward
0 new messages