mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Merge 6febc177d7
into 836e49b535
This commit is contained in:
commit
aaf604c3ac
|
@ -910,7 +910,7 @@ class IntegerField(Field):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
return int(value)
|
return int(value) if value is not None else None
|
||||||
|
|
||||||
|
|
||||||
class FloatField(Field):
|
class FloatField(Field):
|
||||||
|
@ -944,7 +944,7 @@ class FloatField(Field):
|
||||||
self.fail('invalid')
|
self.fail('invalid')
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
return float(value)
|
return float(value) if value is not None else None
|
||||||
|
|
||||||
|
|
||||||
class DecimalField(Field):
|
class DecimalField(Field):
|
||||||
|
|
|
@ -853,6 +853,15 @@ class TestIntegerField(FieldValues):
|
||||||
}
|
}
|
||||||
field = serializers.IntegerField()
|
field = serializers.IntegerField()
|
||||||
|
|
||||||
|
def test_allow_null(self):
|
||||||
|
"""
|
||||||
|
If `allow_null=True` then `None` is a valid input.
|
||||||
|
"""
|
||||||
|
field = serializers.IntegerField(allow_null=True)
|
||||||
|
output = field.run_validation(None)
|
||||||
|
assert output is None
|
||||||
|
assert field.to_representation(None) is None
|
||||||
|
|
||||||
|
|
||||||
class TestMinMaxIntegerField(FieldValues):
|
class TestMinMaxIntegerField(FieldValues):
|
||||||
"""
|
"""
|
||||||
|
@ -899,6 +908,15 @@ class TestFloatField(FieldValues):
|
||||||
}
|
}
|
||||||
field = serializers.FloatField()
|
field = serializers.FloatField()
|
||||||
|
|
||||||
|
def test_allow_null(self):
|
||||||
|
"""
|
||||||
|
If `allow_null=True` then `None` is a valid input.
|
||||||
|
"""
|
||||||
|
field = serializers.FloatField(allow_null=True)
|
||||||
|
output = field.run_validation(None)
|
||||||
|
assert output is None
|
||||||
|
assert field.to_representation(None) is None
|
||||||
|
|
||||||
|
|
||||||
class TestMinMaxFloatField(FieldValues):
|
class TestMinMaxFloatField(FieldValues):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user