diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-01-03 04:59:05 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-01-03 04:59:05 +0000 |
| commit | f2986d89b9fe74ebfc9d544324333c9ebde84ad5 (patch) | |
| tree | 7d32ac618e3c296dc2a9b8da4e39af428402ef34 /django/db/models/fields | |
| parent | 94b83db4995ea8b763fef607141a246cb5c52c37 (diff) | |
[1.0.X] 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.
Backport of r9695 and r9696 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9697 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/fields')
| -rw-r--r-- | django/db/models/fields/__init__.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index afa1c13238..7acb84bcc7 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -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) |
