Skip to main content

normalize_choices

Normalize choices values consistently for fields and widgets.

def normalize_choices(
value: Any,
depth: int = 0
) - > Union[list, Any]

Normalize choices values consistently for fields and widgets.

Parameters

NameTypeDescription
valueAnyThe raw choice data to be normalized, which can be a mapping, iterable, callable, or Django Choices enumeration.
depthint = 0The current recursion depth used to prevent infinite loops and control how nested structures are processed.

Returns

TypeDescription
Union[list, Any]A list of 2-tuples representing the normalized choices, or the original value if it cannot be unpacked or is a lazy/string-like type.