mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
Allow optional max_digits on DecimalField (#4377)
This commit is contained in:
parent
2d43b17f9a
commit
48f3db36d6
|
@ -1016,7 +1016,8 @@ class DecimalField(Field):
|
|||
return value
|
||||
|
||||
context = decimal.getcontext().copy()
|
||||
context.prec = self.max_digits
|
||||
if self.max_digits is not None:
|
||||
context.prec = self.max_digits
|
||||
return value.quantize(
|
||||
decimal.Decimal('.1') ** self.decimal_places,
|
||||
context=context
|
||||
|
|
|
@ -876,6 +876,18 @@ class TestMinMaxDecimalField(FieldValues):
|
|||
)
|
||||
|
||||
|
||||
class TestNoMaxDigitsDecimalField(FieldValues):
|
||||
field = serializers.DecimalField(
|
||||
max_value=100, min_value=0,
|
||||
decimal_places=2, max_digits=None
|
||||
)
|
||||
valid_inputs = {
|
||||
'10': Decimal('10.00')
|
||||
}
|
||||
invalid_inputs = {}
|
||||
outputs = {}
|
||||
|
||||
|
||||
class TestNoStringCoercionDecimalField(FieldValues):
|
||||
"""
|
||||
Output values for `DecimalField` with `coerce_to_string=False`.
|
||||
|
|
Loading…
Reference in New Issue
Block a user