{{{
class BooleanField(Field):
widget = CheckboxInput
def to_python(self, value):
"""Return a Python boolean object."""
# Explicitly check for the string 'False', which is what a hidden
field
# will submit for False. Also check for '0', since this is what
# RadioSelect will provide. Because bool("True") == bool('1') ==
True,
# we don't need to handle that explicitly.
if isinstance(value, str) and value.lower() in ('false', '0'):
value = False
else:
value = bool(value)
return super().to_python(value)
def validate(self, value):
if not value and self.required: # <--- Source of the error this
should likely use `if value is not None and self.required`
raise ValidationError(self.error_messages['required'],
code='required')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32622>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
Ticket URL: <https://code.djangoproject.com/ticket/32622#comment:1>
* component: Uncategorized => Forms
--
Ticket URL: <https://code.djangoproject.com/ticket/32622#comment:2>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #23547.
--
Ticket URL: <https://code.djangoproject.com/ticket/32622#comment:3>