MCPcopy Index your code
hub / github.com/django/django / to_python

Method to_python

django/forms/fields.py:808–818  ·  view source on GitHub ↗

Return a Python boolean object.

(self, value)

Source from the content-addressed store, hash-verified

806 widget = CheckboxInput
807
808 def to_python(self, value):
809 """Return a Python boolean object."""
810 # Explicitly check for the string 'False', which is what a hidden field
811 # will submit for False. Also check for '0', since this is what
812 # RadioSelect will provide. Because bool("True") == bool('1') == True,
813 # we don't need to handle that explicitly.
814 if isinstance(value, str) and value.lower() in ("false", "0"):
815 value = False
816 else:
817 value = bool(value)
818 return super().to_python(value)
819
820 def validate(self, value):
821 if not value and self.required:

Callers 1

has_changedMethod · 0.95

Calls 1

to_pythonMethod · 0.45

Tested by

no test coverage detected