diff options
| author | Tom Christie | 2014-09-11 21:57:32 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-09-11 21:57:32 +0100 | 
| commit | 1e53eb0aa2998385e26aa0a4d8542013bc7b575b (patch) | |
| tree | 4495616efe55dc51c38f557b39f387510669816a /rest_framework | |
| parent | 040bfcc09c851bb3dadd60558c78a1f7937e9fbd (diff) | |
| download | django-rest-framework-1e53eb0aa2998385e26aa0a4d8542013bc7b575b.tar.bz2 | |
DecimalFields should still be quantized even without coerce_to_string
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/fields.py | 8 | 
1 files changed, 5 insertions, 3 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 20b8ffbf..a56ea96b 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -486,9 +486,6 @@ class DecimalField(Field):          return value      def to_primative(self, value): -        if not self.coerce_to_string: -            return value -          if isinstance(value, decimal.Decimal):              context = decimal.getcontext().copy()              context.prec = self.max_digits @@ -496,7 +493,12 @@ class DecimalField(Field):                  decimal.Decimal('.1') ** self.decimal_places,                  context=context              ) +            if not self.coerce_to_string: +                return quantized              return '{0:f}'.format(quantized) + +        if not self.coerce_to_string: +            return value          return '%.*f' % (self.max_decimal_places, value)  | 
