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
| Attribute | Type | Description |
|---|---|---|
| widgets | tuple | A 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
| Name | Type | Description |
|---|---|---|
| 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. |
| attrs | dict = None | Optional 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
| Name | Type | Description |
|---|---|---|
| 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. |
| attrs | dict = None | A 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
| Name | Type | Description |
|---|---|---|
| value | range-like object | The range object containing 'lower' and 'upper' attributes to be split into separate field values. |
Returns
| Type | Description |
|---|---|
tuple | A tuple containing the lower and upper values extracted from the range object, or (None, None) if no value is provided. |