inlineformset_factory
Return an InlineFormSet for the given kwargs.
``fk_name`` must be provided if ``model`` has more than one ``ForeignKey``
to ``parent_model``.
def inlineformset_factory(
parent_model: Model,
model: Model,
form: ModelForm = ModelForm,
formset: BaseInlineFormSet = BaseInlineFormSet,
fk_name: string = null,
fields: list|string = null,
exclude: list = null,
extra: integer = 3,
can_order: boolean = false,
can_delete: boolean = true,
max_num: integer = null,
formfield_callback: callable = null,
widgets: dict = null,
validate_max: boolean = false,
localized_fields: list = null,
labels: dict = null,
help_texts: dict = null,
error_messages: dict = null,
min_num: integer = null,
validate_min: boolean = false,
field_classes: dict = null,
absolute_max: integer = null,
can_delete_extra: boolean = true,
renderer: BaseRenderer = null,
edit_only: boolean = false
) - > class
Return an InlineFormSet for the given kwargs. fk_name must be provided if model has more than one ForeignKey to parent_model.
Parameters
| Name | Type | Description |
|---|---|---|
| parent_model | Model | The model class that represents the 'one' side of the one-to-many relationship. |
| model | Model | The model class that represents the 'many' side of the relationship to be edited inline. |
| form | ModelForm = ModelForm | The form class used to render and validate individual model instances. |
| formset | BaseInlineFormSet = BaseInlineFormSet | The base class to use for the generated formset. |
| fk_name | string = null | The name of the ForeignKey field on the model that points to the parent_model; required if multiple foreign keys exist. |
| fields | `list | string` = null |
| exclude | list = null | A list of field names to exclude from the form. |
| extra | integer = 3 | The number of empty, extra forms to display for adding new objects. |
| can_order | boolean = false | If true, adds a field to each form to allow ordering of the objects. |
| can_delete | boolean = true | If true, adds a checkbox to each form to allow deleting the object. |
| max_num | integer = null | The maximum number of forms to display; automatically set to 1 if the foreign key is unique. |
| formfield_callback | callable = null | A function that takes a model field and returns a form field. |
| widgets | dict = null | A dictionary mapping field names to custom widget classes or instances. |
| validate_max | boolean = false | If true, validation will fail if the number of forms exceeds max_num. |
| localized_fields | list = null | A list of field names that should be localized. |
| labels | dict = null | A dictionary mapping field names to custom label strings. |
| help_texts | dict = null | A dictionary mapping field names to custom help text strings. |
| error_messages | dict = null | A dictionary mapping field names to dictionaries of custom error messages. |
| min_num | integer = null | The minimum number of forms that must be filled out. |
| validate_min | boolean = false | If true, validation will fail if the number of forms is less than min_num. |
| field_classes | dict = null | A dictionary mapping field names to custom form field classes. |
| absolute_max | integer = null | The absolute maximum number of forms allowed, acting as a hard limit for memory protection. |
| can_delete_extra | boolean = true | If true, allows the deletion of extra forms. |
| renderer | BaseRenderer = null | The template renderer used to render the formset. |
| edit_only | boolean = false | If true, prevents the addition of new objects through the formset. |
Returns
| Type | Description |
|---|---|
class | A FormSet class specifically configured to handle related objects via a foreign key relationship. |