Skip to main content

Fieldline

This class represents a single line of fields within a form, managing both standard form fields and read-only fields. It provides an iterator to yield specialized field wrappers for rendering and includes a method to aggregate validation errors for all editable fields in the line. The class also tracks the visibility of its constituent fields to assist in layout management.

Attributes

AttributeTypeDescription
formdjango.forms.FormA django.forms.Form instance used to access field data and validation errors.
fieldslistA list of field names to be rendered together in a single line.
has_visible_fieldbooleanA boolean flag indicating if at least one field in the line is not hidden by its widget.
model_admindjango.contrib.admin.ModelAdminThe ModelAdmin instance associated with the form, used for rendering readonly fields.
readonly_fieldsiterable = ()A collection of field names that should be treated as non-editable within this line.

Constructor

Signature

def Fieldline(
form: django.forms.Form,
field: str or iterable,
readonly_fields: iterable = None,
model_admin: django.contrib.admin.ModelAdmin = None
)

Parameters

NameTypeDescription
formdjango.forms.FormA Django form instance containing the fields.
fieldstr or iterableA single field name or an iterable of field names to be displayed on this line.
readonly_fieldsiterable = NoneA collection of field names that should be rendered as read-only.
model_admindjango.contrib.admin.ModelAdmin = NoneThe ModelAdmin instance associated with the form.

Methods


errors()

@classmethod
def errors() - > [SafeString](../../../utils/safestring/safestring.md?sid=django_utils_safestring_safestring)

Collects and returns the validation errors for all non-readonly fields in the line as a safe HTML string.

Returns

TypeDescription
[SafeString](../../../utils/safestring/safestring.md?sid=django_utils_safestring_safestring)An HTML-safe string containing the concatenated unordered lists of errors for each editable field.