DecimalFields should still be quantized even without coerce_to_string

This commit is contained in:
Tom Christie 2014-09-11 21:57:32 +01:00
parent 040bfcc09c
commit 1e53eb0aa2

View File

@ -486,9 +486,6 @@ class DecimalField(Field):
return value return value
def to_primative(self, value): def to_primative(self, value):
if not self.coerce_to_string:
return value
if isinstance(value, decimal.Decimal): if isinstance(value, decimal.Decimal):
context = decimal.getcontext().copy() context = decimal.getcontext().copy()
context.prec = self.max_digits context.prec = self.max_digits
@ -496,7 +493,12 @@ class DecimalField(Field):
decimal.Decimal('.1') ** self.decimal_places, decimal.Decimal('.1') ** self.decimal_places,
context=context context=context
) )
if not self.coerce_to_string:
return quantized
return '{0:f}'.format(quantized) return '{0:f}'.format(quantized)
if not self.coerce_to_string:
return value
return '%.*f' % (self.max_decimal_places, value) return '%.*f' % (self.max_decimal_places, value)