From 04adfb9c94b2fa68c4f9461fce36091b803840b1 Mon Sep 17 00:00:00 2001 From: Dryice Liu Date: Sun, 28 May 2017 04:14:56 +0800 Subject: [PATCH 1/2] make sure max_length is in FileField kwargs --- rest_framework/utils/field_mapping.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 44c6d4b70..dff33d8b3 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -192,7 +192,8 @@ def get_field_kwargs(field_name, model_field): # rather than as a validator. max_length = getattr(model_field, 'max_length', None) if max_length is not None and (isinstance(model_field, models.CharField) or - isinstance(model_field, models.TextField)): + isinstance(model_field, models.TextField) or + isinstance(model_field, models.FileField)): kwargs['max_length'] = max_length validator_kwarg = [ validator for validator in validator_kwarg From 836328594b2ac9a81cf6e1ecf6cdc204e7387326 Mon Sep 17 00:00:00 2001 From: Dryice Liu Date: Mon, 29 May 2017 08:27:07 +0800 Subject: [PATCH 2/2] add test --- tests/test_model_serializer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index 4aa0fa35e..ba3edd389 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -63,6 +63,7 @@ class RegularFieldsModel(models.Model): slug_field = models.SlugField(max_length=100) small_integer_field = models.SmallIntegerField() text_field = models.TextField(max_length=100) + file_field = models.FileField(max_length=100) time_field = models.TimeField() url_field = models.URLField(max_length=100) custom_field = CustomField() @@ -181,6 +182,7 @@ class TestRegularFieldMappings(TestCase): slug_field = SlugField(max_length=100) small_integer_field = IntegerField() text_field = CharField(max_length=100, style={'base_template': 'textarea.html'}) + file_field = FileField(max_length=100) time_field = TimeField() url_field = URLField(max_length=100) custom_field = ModelField(model_field=)