Esempio n. 1
0
 def to_python(self, value):
     self.validators.append(
         validators.DecimalValidator(self.max_digits, self.decimal_places))
     res = super(UpdatedDecimalField, self).to_python(value)
     converted = res.quantize(
         Decimal(1) / (Decimal(10)**self.decimal_places))
     if converted == res:
         return converted
     else:
         return res
Esempio n. 2
0
 def __init__(self,
              *,
              max_value=None,
              min_value=None,
              max_digits=None,
              decimal_places=None,
              **kwargs):
     self.max_digits, self.decimal_places = max_digits, decimal_places
     super().__init__(max_value=max_value, min_value=min_value, **kwargs)
     self.validators.append(
         validators.DecimalValidator(max_digits, decimal_places))
Esempio n. 3
0
 def validators(self):
     return super().validators + [
         validators.DecimalValidator(self.max_digits, self.decimal_places)
     ]
Esempio n. 4
0
 class XSerializer(serializers.Serializer):
     field = serializers.CharField(validators=[
         validators.DecimalValidator(max_digits=4, decimal_places=2)
     ])
Esempio n. 5
0
 def get_validators(self, validators):
     return super().get_validators(validators) + [
         django_validators.DecimalValidator(self.type.precision,
                                            self.type.scale)
     ]