West
West

Reputation: 2570

Where does the base_fields dictionary in django ManagementForm class come from?

I'm trying to improve my understanding of using forms in django and looking at the docs I'm confused of where the base_fields dictionary comes from in ManagementForm class?Hope someone can help me understand. Initially I thought its passed in by some other method but I cant seem to find which one.

class ManagementForm(Form):
    """
    Keep track of how many form instances are displayed on the page. If adding
    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)

Source code: https://docs.djangoproject.com/en/2.2/_modules/django/forms/formsets/#BaseFormSet

Upvotes: 1

Views: 485

Answers (1)

Kent Shikama
Kent Shikama

Reputation: 4060

It is originally declared in the metaclass of the Form class.

For whatever reason I have found myself walking through the Django source more often than any other framework I've used, especially related to forms.

Upvotes: 2

Related Questions