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
| Attribute | Type | Description |
|---|---|---|
| form | django.forms.Form | A django.forms.Form instance used to access field data and validation errors. |
| fields | list | A list of field names to be rendered together in a single line. |
| has_visible_field | boolean | A boolean flag indicating if at least one field in the line is not hidden by its widget. |
| model_admin | django.contrib.admin.ModelAdmin | The ModelAdmin instance associated with the form, used for rendering readonly fields. |
| readonly_fields | iterable = () | 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
| Name | Type | Description |
|---|---|---|
| form | django.forms.Form | A Django form instance containing the fields. |
| field | str or iterable | A single field name or an iterable of field names to be displayed on this line. |
| readonly_fields | iterable = None | A collection of field names that should be rendered as read-only. |
| model_admin | django.contrib.admin.ModelAdmin = None | The 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
| Type | Description |
|---|---|
[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. |