From a71acc76d8ede28ad9c5f9fd0fc129f6321c9231 Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Sat, 18 May 2013 15:12:54 +0200 Subject: Fix for #710 --- rest_framework/serializers.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'rest_framework/serializers.py') 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: -- cgit v1.2.3 From b7176065a9aafb3d560f9e8c2e420bd4cc5841dc Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Sat, 18 May 2013 16:06:30 +0200 Subject: Update getattr --- rest_framework/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/serializers.py') diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 1b451f2d..338803fe 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -737,7 +737,7 @@ class ModelSerializer(Serializer): if model_field.__class__ in attribute_dict: attributes = attribute_dict[model_field.__class__] for attribute in attributes: - kwargs.update({attribute: model_field.__getattribute__(attribute)}) + kwargs.update({attribute: getattr(model_field, attribute)}) try: return self.field_mapping[model_field.__class__](**kwargs) -- cgit v1.2.3