NullBooleanField
A field whose valid values are None, True, and False. Clean invalid values to None.
Attributes
| Attribute | Type | Description |
|---|---|---|
| widget | [Widget](../widgets/widget.md?sid=django_forms_widgets_widget) = NullBooleanSelect | The default widget class used to render this field in HTML forms, specifically designed to handle the three-state selection of None, True, and False. |
Methods
to_python()
@classmethod
def to_python(
value: any
) - > boolean
Explicitly check for the string 'True' and 'False', which is what a hidden field will submit for True and False, for 'true' and 'false', which are likely to be returned by JavaScript serializations of forms, and for '1' and '0', which is what a RadioField will submit. Unlike the Booleanfield, this field must check for True because it doesn't use the bool() function.
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The raw input value from a form submission, JavaScript serialization, or hidden field to be converted into a Python boolean or None. |
Returns
| Type | Description |
|---|---|
boolean | Returns True or False if the input matches a boolean-like value, otherwise returns None. |
validate()
@classmethod
def validate(
value: any
) - > null
Performs no validation on the provided value, allowing any input that has been processed by to_python to pass.
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The Python-converted value to be validated against field constraints. |
Returns
| Type | Description |
|---|---|
null | Always returns None. |