#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.