Skip to main content

AdminField

This class acts as a wrapper for a form field within the administrative interface, managing its display properties and metadata. It determines the field's visual state, such as whether it is a checkbox, a readonly element, or the first item in a row. Additionally, it provides methods to generate specialized HTML label tags and error lists tailored for admin templates.

Attributes

AttributeTypeDescription
fielddjango.forms.BoundFieldThe Django BoundField instance representing the specific form field being rendered.
is_firstbooleanA boolean flag indicating whether this field is the first element on its current display line.
is_checkboxbooleanA boolean flag that identifies if the field's widget is a CheckboxInput, used to determine CSS classes and label positioning.
is_readonlyboolean = falseA boolean flag indicating whether the field is in a read-only state within the admin interface.
is_fieldsetbooleanA boolean flag derived from the widget's use_fieldset property that determines if the field should be wrapped in a fieldset/legend structure.

Constructor

Signature

def AdminField(
form: django.forms.BaseForm,
field: str,
is_first: bool
)

Parameters

NameTypeDescription
formdjango.forms.BaseFormThe form instance containing the field.
fieldstrThe name of the field to be retrieved from the form.
is_firstboolA flag indicating if this field is the first element on its display line.

Methods


label_tag()

@classmethod
def label_tag() - > string

Generates the HTML label or legend tag for the field, applying specific CSS classes based on whether the field is required, a checkbox, or positioned inline.

Returns

TypeDescription
stringThe rendered HTML tag containing the field label and appropriate styling attributes.

errors()

@classmethod
def errors() - > string

Returns the validation errors associated with the field formatted as an HTML unordered list.

Returns

TypeDescription
stringA safe HTML string containing the list of field errors, or an empty string if no errors exist.