Validator-fix, added min/max fields to test_metadata

This commit is contained in:
Rense VanderHoek 2015-02-20 17:34:49 +01:00
parent c8609ba652
commit 9cb547b85f
2 changed files with 15 additions and 6 deletions

View File

@ -738,10 +738,10 @@ class DecimalField(Field):
super(DecimalField, self).__init__(**kwargs)
if self.max_value is not None:
message = self.error_messages['max_value'].format(max_value=self.max_value)
self.validators.append(MaxValueValidator(max_value, message=message))
self.validators.append(MaxValueValidator(self.max_value, message=message))
if self.min_value is not None:
message = self.error_messages['min_value'].format(min_value=self.min_value)
self.validators.append(MinValueValidator(min_value, message=message))
self.validators.append(MinValueValidator(self.min_value, message=message))
def to_internal_value(self, data):
"""

View File

@ -54,8 +54,12 @@ class TestMetadata:
"""
class ExampleSerializer(serializers.Serializer):
choice_field = serializers.ChoiceField(['red', 'green', 'blue'])
integer_field = serializers.IntegerField(max_value=10)
char_field = serializers.CharField(required=False)
integer_field = serializers.IntegerField(
min_value=1, max_value=1000
)
char_field = serializers.CharField(
required=False, min_length=3, max_length=40
)
class ExampleView(views.APIView):
"""Example view."""
@ -96,13 +100,18 @@ class TestMetadata:
'type': 'integer',
'required': True,
'read_only': False,
'label': 'Integer field'
'label': 'Integer field',
'min_value': 1,
'max_value': 1000,
},
'char_field': {
'type': 'string',
'required': False,
'read_only': False,
'label': 'Char field'
'label': 'Char field',
'min_length': 3,
'max_length': 40
}
}
}