mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Return Decimal instance instead of string
This commit is contained in:
parent
9d80f01bce
commit
cac6697025
|
@ -761,11 +761,6 @@ class DecimalField(WritableField):
|
||||||
raise ValidationError(self.error_messages['invalid'])
|
raise ValidationError(self.error_messages['invalid'])
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def to_native(self, value):
|
|
||||||
if value is not None:
|
|
||||||
return str(value)
|
|
||||||
return value
|
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
super(DecimalField, self).validate(value)
|
super(DecimalField, self).validate(value)
|
||||||
if value in validators.EMPTY_VALUES:
|
if value in validators.EMPTY_VALUES:
|
||||||
|
|
|
@ -559,8 +559,8 @@ class DecimalFieldTest(TestCase):
|
||||||
result_1 = f.to_native(Decimal('9000'))
|
result_1 = f.to_native(Decimal('9000'))
|
||||||
result_2 = f.to_native(Decimal('1.00000001'))
|
result_2 = f.to_native(Decimal('1.00000001'))
|
||||||
|
|
||||||
self.assertEqual('9000', result_1)
|
self.assertEqual(Decimal('9000'), result_1)
|
||||||
self.assertEqual('1.00000001', result_2)
|
self.assertEqual(Decimal('1.00000001'), result_2)
|
||||||
|
|
||||||
def test_to_native_none(self):
|
def test_to_native_none(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user