Skip to main content

formset_factory

Return a FormSet for the given form class.

def formset_factory(
form: type,
formset: type = BaseFormSet,
extra: int = 1,
can_order: bool = False,
can_delete: bool = False,
max_num: int = None,
validate_max: bool = False,
min_num: int = None,
validate_min: bool = False,
absolute_max: int = None,
can_delete_extra: bool = True,
renderer: object = None
) - > type

Return a FormSet for the given form class.

Parameters

NameTypeDescription
formtypeThe base form class that will be used to instantiate individual forms within the set.
formsettype = BaseFormSetThe base class from which the new FormSet class will inherit.
extraint = 1The number of empty forms to display in addition to any initial data forms.
can_orderbool = FalseWhether to provide an ordering field for each form to allow manual reordering.
can_deletebool = FalseWhether to provide a checkbox for each form to allow deletion of existing records.
max_numint = NoneThe maximum number of forms that can be displayed or submitted.
validate_maxbool = FalseIf True, validation will fail if the number of forms exceeds max_num.
min_numint = NoneThe minimum number of forms that must be submitted.
validate_minbool = FalseIf True, validation will fail if the number of forms is less than min_num.
absolute_maxint = NoneA hard limit on the number of forms instantiated to prevent memory-exhaustion attacks; must be greater than or equal to max_num.
can_delete_extrabool = TrueWhether extra forms are allowed to be marked for deletion.
rendererobject = NoneThe engine used to render the formset into HTML.

Returns

TypeDescription
typeA dynamically created FormSet class tailored to the provided form and configuration options.