modelform_factory
Return a ModelForm containing form fields for the given model. You can optionally pass a form argument to use as a starting point for constructing the ModelForm.
def modelform_factory(
model: Model,
form: ModelForm = ModelForm,
fields: list|str = None,
exclude: list = None,
formfield_callback: callable = None,
widgets: dict = None,
localized_fields: list = None,
labels: dict = None,
help_texts: dict = None,
error_messages: dict = None,
field_classes: dict = None
) - > ModelForm
Return a ModelForm containing form fields for the given model. You can optionally pass a form argument to use as a starting point for constructing the ModelForm.
Parameters
| Name | Type | Description |
|---|---|---|
| model | Model | The Django model class that the factory will use to generate form fields. |
| form | ModelForm = ModelForm | The base class to use as a starting point for constructing the new ModelForm. |
| fields | `list | str` = None |
| exclude | list = None | An optional list of field names to exclude from the form, even if they are present in the fields list. |
| formfield_callback | callable = None | A callable that takes a model field and returns a custom form field instance. |
| widgets | dict = None | A dictionary mapping model field names to specific UI widget classes. |
| localized_fields | list = None | A list of field names that should be enabled for localization. |
| labels | dict = None | A dictionary mapping model field names to custom display labels. |
| help_texts | dict = None | A dictionary mapping model field names to custom help text strings. |
| error_messages | dict = None | A dictionary mapping model field names to dictionaries of custom error messages. |
| field_classes | dict = None | A dictionary mapping model field names to specific form field classes. |
Returns
| Type | Description |
|---|---|
ModelForm | A dynamically created ModelForm class tailored to the specified model and configuration. |