diff options
| author | Tom Christie | 2013-05-18 07:19:52 -0700 |
|---|---|---|
| committer | Tom Christie | 2013-05-18 07:19:52 -0700 |
| commit | cc39b9c9256896c5106b7f265af77f8db8a9f2b5 (patch) | |
| tree | 385c803894a9940a7f3e8b81033d8c588c960899 /rest_framework/serializers.py | |
| parent | 3ba43b960ecacda1121670440a38c2883815bad2 (diff) | |
| parent | b7176065a9aafb3d560f9e8c2e420bd4cc5841dc (diff) | |
| download | django-rest-framework-cc39b9c9256896c5106b7f265af77f8db8a9f2b5.tar.bz2 | |
Merge pull request #858 from minddust/fix_710
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 9cfeed37..229b2cde 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -727,6 +727,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: getattr(model_field, attribute)}) + try: return self.field_mapping[model_field.__class__](**kwargs) except KeyError: |
