MCPcopy
hub / github.com/django/django / to_python

Method to_python

django/forms/fields.py:511–520  ·  view source on GitHub ↗

Validate that the input can be converted to a time. Return a Python datetime.time object.

(self, value)

Source from the content-addressed store, hash-verified

509 default_error_messages = {"invalid": _("Enter a valid time.")}
510
511 def to_python(self, value):
512 """
513 Validate that the input can be converted to a time. Return a Python
514 datetime.time object.
515 """
516 if value in self.empty_values:
517 return None
518 if isinstance(value, datetime.time):
519 return value
520 return super().to_python(value)
521
522 def strptime(self, value, format):
523 return datetime.datetime.strptime(value, format).time()

Calls 1

to_pythonMethod · 0.45

Tested by 1