mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #9942 -- Added a to_python handler for FloatField to ensure correct typing of deserialized data before saving. Underlying problem is analogous to #8298, fixed in [8515]. Thanks to David Larlet <larlet@gmail.com> for the report and fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9695 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -658,6 +658,15 @@ class FloatField(Field):
|
||||
def get_internal_type(self):
|
||||
return "FloatField"
|
||||
|
||||
def to_python(self, value):
|
||||
if value is None:
|
||||
return value
|
||||
try:
|
||||
return float(value)
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.ValidationError(
|
||||
_("This value must be a float."))
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'form_class': forms.FloatField}
|
||||
defaults.update(kwargs)
|
||||
|
||||
Reference in New Issue
Block a user