Forms API Reference

Form Widgets

class ldaporm.forms.CharListWidget(attrs=None)[source]

Bases: Textarea

A Textarea subclass for handling lists of character strings. This is used as the default widget for the CharListField field.

This widget converts between a list of strings and a newline-separated text format for display in forms. It handles empty values appropriately and provides a user-friendly interface for editing string lists.

render(name: str, value: str | list[str] | None, attrs: dict[str, Any] | None = None, renderer: BaseRenderer | None = None) str[source]

Render the widget as HTML.

Parameters:
  • name – The name attribute for the form field.

  • value – The current value, which can be a string, list of strings, or None.

  • attrs – Additional HTML attributes for the widget.

  • renderer – The form renderer to use.

Returns:

The rendered HTML string for the widget.

is_hidden: bool = False
property media
class ldaporm.forms.CharListField(*, max_length=None, min_length=None, strip=True, empty_value='', **kwargs)[source]

Bases: CharField

A form field for handling lists of character strings. This is the default field for the CharListWidget widget on django.forms.ModelForm.

This field extends CharField to handle lists of strings, converting between newline-separated text input and Python lists. It validates each line independently and provides appropriate error handling.

widget

The widget class to use for this field.

alias of CharListWidget

run_validators(value: list[str]) None[source]

Validate each line independently.

This method runs the parent field’s validators on each individual string in the list, collecting all validation errors.

Parameters:

value – The list of strings to validate.

Raises:

ValidationError – If any validation fails, containing all error messages.

to_python(value: str | None) list[str][source]

Convert the input value to a Python list of strings.

Parameters:

value – The input value, which can be a string or None.

Returns:

A list of strings. Empty input returns an empty list.

widget_attrs(widget: Widget) dict[str, Any][source]

Get HTML attributes for the widget.

Parameters:

widget – The widget instance to get attributes for.

Returns:

A dictionary of HTML attributes for the widget.

empty_values: list[Any] = [None, '', [], (), {}, '[]']