Skip to content

Form Fields

fields

ChoiceFieldNoValidation

Bases: ChoiceField

ChoiceField that skips server-side choice validation.

Use when choices are populated dynamically via JavaScript on the client side, so the submitted value may not be in the server-defined choices list.

Example
class MyForm(forms.Form):
    category = ChoiceFieldNoValidation(choices=[])

CheckboxMultipleChoiceField(*args, **kwargs)

Bases: MultipleChoiceField

MultipleChoiceField that renders as checkboxes and handles JSON serialization.

Used as the default form field for MultipleChoiceField (model field). Accepts and produces Python lists; handles JSON string input from the database transparently.

to_python(value)

Override to handle JSON string values properly

validate(value)

Override validation to handle our custom data format

USAddressFormField(*args, **kwargs)

Bases: Field

Form field for US addresses with multi-component input and validation.

Renders as five separate inputs (street, street line 2, city, state dropdown, ZIP code) via USAddressWidget. Produces a dict with keys street_address, street_address_2, city, state, zip_code.

Validates that required address components are present, state is a 2-letter code, and ZIP matches XXXXX or XXXXX-XXXX format.

This is the default form field for USAddressField (model field) and is normally not used directly.

to_python(value)

Convert form data to Python object

validate(value)

Validate the address data

prepare_value(value)

Prepare value for display in the widget

CurrencyFormField(*args, **kwargs)

Bases: DecimalField

DecimalField for currency input with client-side formatting.

Defaults to max_digits=10 and decimal_places=2. Uses CurrencyInput widget which adds $ sign and comma separators via JavaScript on blur.

This is the default form field for CurrencyField (model field).