fix-#787: Fix storing value of precision attribute in DecimalField

This commit is contained in:
DavidBord 2014-11-07 15:03:11 +02:00
parent 201b12a886
commit 1fcf009804
2 changed files with 3 additions and 2 deletions

View File

@ -5,6 +5,7 @@ Changelog
Changes in 0.9.X - DEV
======================
- Fix storing value of precision attribute in DecimalField #787
- Querying by a field defined in a subclass raises InvalidQueryError #744
- Add Support For MongoDB 2.6.X's maxTimeMS #778
- abstract shouldn't be inherited in EmbeddedDocument # 789

View File

@ -308,7 +308,7 @@ class DecimalField(BaseField):
self.min_value = min_value
self.max_value = max_value
self.force_string = force_string
self.precision = decimal.Decimal(".%s" % ("0" * precision))
self.precision = precision
self.rounding = rounding
super(DecimalField, self).__init__(**kwargs)
@ -322,7 +322,7 @@ class DecimalField(BaseField):
value = decimal.Decimal("%s" % value)
except decimal.InvalidOperation:
return value
return value.quantize(self.precision, rounding=self.rounding)
return value.quantize(decimal.Decimal(".%s" % ("0" * self.precision)), rounding=self.rounding)
def to_mongo(self, value, use_db_field=True):
if value is None: