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

Method to_python

django/forms/fields.py:369–383  ·  view source on GitHub ↗

Validate that float() can be called on the input. Return the result of float() or None for empty values.

(self, value)

Source from the content-addressed store, hash-verified

367 }
368
369 def to_python(self, value):
370 """
371 Validate that float() can be called on the input. Return the result
372 of float() or None for empty values.
373 """
374 value = super(IntegerField, self).to_python(value)
375 if value in self.empty_values:
376 return None
377 if self.localize:
378 value = formats.sanitize_separators(value)
379 try:
380 value = float(value)
381 except (ValueError, TypeError):
382 raise ValidationError(self.error_messages["invalid"], code="invalid")
383 return value
384
385 def validate(self, value):
386 super().validate(value)

Callers

nothing calls this directly

Calls 2

ValidationErrorClass · 0.90
to_pythonMethod · 0.45

Tested by

no test coverage detected