Moved ManagementForm's fields to class attributes.
This helps introspection, and it follows the comment in
BaseForm.__init__() to avoid changing base_fields.
Thanks to Silvio Gutierrez and Baptiste Mispelon for investigating.
@@ -30,15 +30,13 @@ class ManagementForm(Form):
new forms via JavaScript, you should increment the count field of this form
as well.
"""
- def __init__(self, *args, **kwargs):
- self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput)
- self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput)
- # MIN_NUM_FORM_COUNT and MAX_NUM_FORM_COUNT are output with the rest of
- # the management form, but only for the convenience of client-side
- # code. The POST value of them returned from the client is not checked.
- self.base_fields[MIN_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput)
- self.base_fields[MAX_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput)
- super().__init__(*args, **kwargs)
+ 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
+ # management form, but only for the convenience of client-side code. The
+ # POST value of them returned from the client is not checked.
+ MIN_NUM_FORMS = IntegerField(required=False, widget=HiddenInput)
+ MAX_NUM_FORMS = IntegerField(required=False, widget=HiddenInput)
def clean(self):
cleaned_data = super().clean()
