Commit 4db23cae by Tom Christie

Tweaks to DecimalField

parent 249253a1
...@@ -521,7 +521,12 @@ class DecimalField(Field): ...@@ -521,7 +521,12 @@ class DecimalField(Field):
return value return value
def to_representation(self, value): def to_representation(self, value):
if isinstance(value, decimal.Decimal): if value in (None, ''):
return None
if not isinstance(value, decimal.Decimal):
value = decimal.Decimal(value)
context = decimal.getcontext().copy() context = decimal.getcontext().copy()
context.prec = self.max_digits context.prec = self.max_digits
quantized = value.quantize( quantized = value.quantize(
...@@ -532,10 +537,6 @@ class DecimalField(Field): ...@@ -532,10 +537,6 @@ class DecimalField(Field):
return quantized 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)
# Date & time fields... # Date & time fields...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment