Commit 4db23cae by Tom Christie

Tweaks to DecimalField

parent 249253a1
......@@ -521,7 +521,12 @@ class DecimalField(Field):
return 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.prec = self.max_digits
quantized = value.quantize(
......@@ -532,10 +537,6 @@ class DecimalField(Field):
return quantized
return '{0:f}'.format(quantized)
if not self.coerce_to_string:
return value
return '%.*f' % (self.max_decimal_places, value)
# 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