Skip to main content

RangeWidget

This class provides a user interface widget for handling range-based data by wrapping two instances of a base widget. It facilitates the input of lower and upper bounds and includes logic to decompress range objects into individual values for the underlying widgets.

Attributes

AttributeTypeDescription
widgetstupleA tuple containing two instances of the base_widget used to render the lower and upper bounds of the range.

Constructor

Signature

def RangeWidget(
base_widget: [Widget](../../../../forms/widgets/widget.md?sid=django_forms_widgets_widget),
attrs: dict = None
) - > null

Parameters

NameTypeDescription
base_widget[Widget](../../../../forms/widgets/widget.md?sid=django_forms_widgets_widget)The widget class or instance to be used for both the start and end of the range.
attrsdict = NoneOptional HTML attributes to be rendered on the widgets.

Signature

def RangeWidget(
base_widget: [Widget](../../../../forms/widgets/widget.md?sid=django_forms_widgets_widget),
attrs: dict = None
) - > null

Parameters

NameTypeDescription
base_widget[Widget](../../../../forms/widgets/widget.md?sid=django_forms_widgets_widget)The Django widget class or instance used for both the lower and upper bound inputs.
attrsdict = NoneA dictionary of HTML attributes to be added to the rendered widget elements.

Methods


decompress()

@classmethod
def decompress(
value: range-like object
) - > tuple

Converts a single range object into a tuple representing the lower and upper bounds for display in the individual widgets.

Parameters

NameTypeDescription
valuerange-like objectThe range object containing 'lower' and 'upper' attributes to be split into separate field values.

Returns

TypeDescription
tupleA tuple containing the lower and upper values extracted from the range object, or (None, None) if no value is provided.