From e399140031a0738a054f5f07e42ef7208f9e45f4 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 7 Nov 2014 10:51:08 +0000 Subject: [PATCH] Minor tweaks --- rest_framework/serializers.py | 6 ++++++ rest_framework/utils/field_mapping.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 68ea27ab6..b00f9b7a8 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -393,6 +393,9 @@ class ListSerializer(BaseSerializer): return ReturnList(serializer=self) def get_value(self, dictionary): + """ + Given the input dictionary, return the field value. + """ # We override the default field access in order to support # lists in HTML forms. if html.is_html_input(dictionary): @@ -442,6 +445,9 @@ class ListSerializer(BaseSerializer): ) def save(self, **kwargs): + """ + Save and return a list of object instances. + """ assert self.instance is None, ( "Serializers do not support multiple update by default, only " "multiple create. For updates it is unclear how to deal with " diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 6db371469..246390853 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -219,9 +219,11 @@ def get_relation_kwargs(field_name, relation_info): kwargs['required'] = False if model_field.null: kwargs['allow_null'] = True + if model_field.validators: + kwargs['validators'] = model_field.validators if getattr(model_field, 'unique', False): validator = UniqueValidator(queryset=model_field.model._default_manager) - kwargs['validators'] = [validator] + kwargs['validators'] = kwargs.get('validators', []) + [validator] return kwargs