diff --git a/rest_framework/fields.py b/rest_framework/fields.py index bea773001..ed0270a59 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -682,7 +682,7 @@ class IntegerField(Field): self.fail('max_string_length') try: - data = int(data) + data = int(re.compile(r'\.0*\s*$').sub('', str(data))) except (ValueError, TypeError): self.fail('invalid') return data diff --git a/tests/test_fields.py b/tests/test_fields.py index 1aa528da6..da6bd6ceb 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -549,10 +549,13 @@ class TestIntegerField(FieldValues): 1: 1, 0: 0, 1.0: 1, - 0.0: 0 + 0.0: 0, + '1.0': 1 } invalid_inputs = { - 'abc': ['A valid integer is required.'] + 0.5: ['A valid integer is required.'], + 'abc': ['A valid integer is required.'], + '0.5': ['A valid integer is required.'] } outputs = { '1': 1,