Skip to main content

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

AttributeTypeDescription
modelModel class = nullThe Django model class that this form is linked to for data persistence and validation.
fieldslist, tuple, or string = nullA list or tuple of field names to include in the form, or the special value 'all' to include all model fields.
excludelist or tuple = nullA list or tuple of field names from the model that should be omitted from the form representation.
widgetsdict = nullA dictionary mapping field names to custom widget classes or instances to override default form rendering.
localized_fieldslist or tuple = nullA collection of field names that should be localized for input and output based on the current locale.
labelsdict = nullA dictionary mapping field names to custom display labels used in the rendered HTML form.
help_textsdict = nullA dictionary mapping field names to custom help text strings displayed alongside the form fields.
error_messagesdict = nullA dictionary mapping field names to dictionaries of custom error messages for specific validation failures.
field_classesdict = nullA dictionary mapping field names to custom form field classes to override the default field types derived from the model.
formfield_callbackcallable = nullA callable used to customize the creation of form fields from model fields during form initialization.

Constructor

Signature

def ModelFormOptions(
options: object = None
) - > null

Parameters

NameTypeDescription
optionsobject = NoneAn object containing configuration attributes for the model form.

Signature

def ModelFormOptions(
options: object = None
) - > null

Parameters

NameTypeDescription
optionsobject = NoneAn object containing configuration attributes such as model, fields, exclude, and widgets used to define the ModelForm behavior.