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

Method to_python

django/forms/fields.py:489–500  ·  view source on GitHub ↗

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

(self, value)

Source from the content-addressed store, hash-verified

487 }
488
489 def to_python(self, value):
490 """
491 Validate that the input can be converted to a date. Return a Python
492 datetime.date object.
493 """
494 if value in self.empty_values:
495 return None
496 if isinstance(value, datetime.datetime):
497 return value.date()
498 if isinstance(value, datetime.date):
499 return value
500 return super().to_python(value)
501
502 def strptime(self, value, format):
503 return datetime.datetime.strptime(value, format).date()

Callers

nothing calls this directly

Calls 1

to_pythonMethod · 0.45

Tested by

no test coverage detected