ModelFormOptions
This class serves as a configuration container for defining the behavior and metadata of a model-based form. It extracts and stores various attributes such as the associated model, included or excluded fields, custom widgets, labels, and error messages from a provided options object. By centralizing these settings, it facilitates the automated generation and customization of form fields based on model definitions.
Attributes
| Attribute | Type | Description |
|---|---|---|
| model | Model class = null | The Django model class that this form is linked to for data persistence and validation. |
| fields | list, tuple, or string = null | A list or tuple of field names to include in the form, or the special value 'all' to include all model fields. |
| exclude | list or tuple = null | A list or tuple of field names from the model that should be omitted from the form representation. |
| widgets | dict = null | A dictionary mapping field names to custom widget classes or instances to override default form rendering. |
| localized_fields | list or tuple = null | A collection of field names that should be localized for input and output based on the current locale. |
| labels | dict = null | A dictionary mapping field names to custom display labels used in the rendered HTML form. |
| help_texts | dict = null | A dictionary mapping field names to custom help text strings displayed alongside the form fields. |
| error_messages | dict = null | A dictionary mapping field names to dictionaries of custom error messages for specific validation failures. |
| field_classes | dict = null | A dictionary mapping field names to custom form field classes to override the default field types derived from the model. |
| formfield_callback | callable = null | A callable used to customize the creation of form fields from model fields during form initialization. |
Constructor
Signature
def ModelFormOptions(
options: object = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| options | object = None | An object containing configuration attributes for the model form. |
Signature
def ModelFormOptions(
options: object = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| options | object = None | An object containing configuration attributes such as model, fields, exclude, and widgets used to define the ModelForm behavior. |