Skip to main content

AdminForm

This class acts as a wrapper for a form and its associated fieldsets to facilitate rendering within an administration interface. It manages prepopulated fields, read-only fields, and fieldset organization while providing access to form errors and media. The class is designed to be iterable, yielding individual fieldset objects for structured display.

Attributes

AttributeTypeDescription
formdjango.forms.FormThe Django form instance used to manage data validation and field rendering.
fieldsetsiterableAn iterable of fieldset configurations defining the grouping and layout of form fields.
prepopulated_fieldslistA list of dictionaries mapping form fields to their dependent fields for automatic value generation.
model_admindjango.contrib.admin.ModelAdminThe ModelAdmin instance associated with this form, providing administrative context and logic.
readonly_fieldstuple = ()A collection of field names that should be rendered as non-editable text within the form.
errorsdjango.forms.utils.ErrorDictReturns the collection of validation errors associated with the underlying form.
non_field_errorsdjango.forms.utils.ErrorListReturns errors from the underlying form that are not associated with a specific field.
fieldsdictProvides access to the dictionary of form fields defined in the underlying form instance.
is_boundbooleanIndicates whether the underlying form has data bound to it for validation.
mediadjango.forms.widgets.MediaThe combined media definitions for the form and all associated fieldsets, including CSS and JavaScript.

Constructor

Signature

def AdminForm(
form: django.forms.Form,
fieldsets: list,
prepopulated_fields: dict,
readonly_fields: list = None,
model_admin: django.contrib.admin.ModelAdmin = None
) - > null

Parameters

NameTypeDescription
formdjango.forms.FormThe form instance to be rendered.
fieldsetslistA list of fieldsets defining the layout of the form.
prepopulated_fieldsdictA dictionary mapping field names to their dependencies for automatic population.
readonly_fieldslist = NoneA list of fields that should be rendered as read-only.
model_admindjango.contrib.admin.ModelAdmin = NoneThe ModelAdmin instance associated with the form.

Methods


errors()

@classmethod
def errors() - > [ErrorDict](../../../forms/utils/errordict.md?sid=django_forms_utils_errordict)

Accesses the collection of validation errors associated with the underlying form instance.

Returns

TypeDescription
[ErrorDict](../../../forms/utils/errordict.md?sid=django_forms_utils_errordict)A dictionary-like object mapping field names to their respective list of error messages.

non_field_errors()

@classmethod
def non_field_errors() - > [ErrorList](../../../forms/utils/errorlist.md?sid=django_forms_utils_errorlist)

Retrieves errors that are not specific to a particular field, such as those originating from the form's clean() method.

Returns

TypeDescription
[ErrorList](../../../forms/utils/errorlist.md?sid=django_forms_utils_errorlist)A list of error messages that apply to the form as a whole.

fields()

@classmethod
def fields() - > dict

Provides access to the dictionary of bound or unbound field objects defined on the underlying form.

Returns

TypeDescription
dictA dictionary mapping field names to form field objects.

is_bound()

@classmethod
def is_bound() - > boolean

Indicates whether the underlying form has been provided with data to validate.

Returns

TypeDescription
booleanTrue if the form has data or files attached, False otherwise.

media()

@classmethod
def media() - > [Media](../../../forms/widgets/media.md?sid=django_forms_widgets_media)

Aggregates the required JavaScript and CSS assets from both the underlying form and all individual fieldsets.

Returns

TypeDescription
[Media](../../../forms/widgets/media.md?sid=django_forms_widgets_media)A Media object containing the combined static file paths for the form and its fieldsets.