diff options
| author | Stephan Groß | 2013-05-18 15:12:54 +0200 | 
|---|---|---|
| committer | Stephan Groß | 2013-05-18 15:12:54 +0200 | 
| commit | a71acc76d8ede28ad9c5f9fd0fc129f6321c9231 (patch) | |
| tree | 67229a31a95f7185ee52c4b511f9f146a509ec80 /rest_framework/serializers.py | |
| parent | a0e3c44c99a61a6dc878308bdf0890fbb10c41e4 (diff) | |
| download | django-rest-framework-a71acc76d8ede28ad9c5f9fd0fc129f6321c9231.tar.bz2 | |
Fix for #710
Diffstat (limited to 'rest_framework/serializers.py')
| -rw-r--r-- | rest_framework/serializers.py | 16 | 
1 files changed, 16 insertions, 0 deletions
| diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 500bb306..1b451f2d 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -723,6 +723,22 @@ class ModelSerializer(Serializer):              kwargs['choices'] = model_field.flatchoices              return ChoiceField(**kwargs) +        attribute_dict = { +            models.CharField: ['max_length'], +            models.CommaSeparatedIntegerField: ['max_length'], +            models.DecimalField: ['max_digits', 'decimal_places'], +            models.EmailField: ['max_length'], +            models.FileField: ['max_length'], +            models.ImageField: ['max_length'], +            models.SlugField: ['max_length'], +            models.URLField: ['max_length'], +        } + +        if model_field.__class__ in attribute_dict: +            attributes = attribute_dict[model_field.__class__] +            for attribute in attributes: +                kwargs.update({attribute: model_field.__getattribute__(attribute)}) +          try:              return self.field_mapping[model_field.__class__](**kwargs)          except KeyError: | 
