fix DecimalField precision
fix decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>] error if DecimalField param precision is zero or less
This commit is contained in:
parent
4670508a1c
commit
09c415a416
@ -482,10 +482,11 @@ class DecimalField(BaseField):
|
|||||||
value = decimal.Decimal("%s" % value)
|
value = decimal.Decimal("%s" % value)
|
||||||
except (TypeError, ValueError, decimal.InvalidOperation):
|
except (TypeError, ValueError, decimal.InvalidOperation):
|
||||||
return value
|
return value
|
||||||
return value.quantize(
|
if self.precision > 0:
|
||||||
decimal.Decimal(".%s" % ("0" * self.precision)), rounding=self.rounding
|
return value.quantize(decimal.Decimal(".%s" % ("0" * self.precision)), rounding=self.rounding)
|
||||||
)
|
else:
|
||||||
|
return value.quantize(decimal.Decimal(), rounding=self.rounding)
|
||||||
|
|
||||||
def to_mongo(self, value):
|
def to_mongo(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user