diff options
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/fields.py | 13 | ||||
| -rw-r--r-- | rest_framework/routers.py | 16 | 
2 files changed, 15 insertions, 14 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index c40dc3fb..aab80982 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -273,7 +273,11 @@ class Field(object):                      return empty                  return self.default_empty_html              ret = dictionary[self.field_name] -            return self.default_empty_html if (ret == '') else ret +            if ret == '' and self.allow_null: +                # If the field is blank, and null is a valid value then +                # determine if we should use null instead. +                return '' if getattr(self, 'allow_blank', False) else None +            return ret          return dictionary.get(self.field_name, empty)      def get_attribute(self, instance): @@ -545,8 +549,6 @@ class CharField(Field):          'min_length': _('Ensure this field has at least {min_length} characters.')      }      initial = '' -    coerce_blank_to_null = False -    default_empty_html = ''      def __init__(self, **kwargs):          self.allow_blank = kwargs.pop('allow_blank', False) @@ -560,11 +562,6 @@ class CharField(Field):              message = self.error_messages['min_length'].format(min_length=min_length)              self.validators.append(MinLengthValidator(min_length, message=message)) -        if self.allow_null and (not self.allow_blank) and (self.default is empty): -            # HTML input cannot represent `None` values, so we need to -            # forcibly coerce empty HTML values to `None` if `allow_null=True`. -            self.default_empty_html = None -      def run_validation(self, data=empty):          # Test for the empty string here so that it does not get validated,          # and so that subclasses do not need to handle it explicitly diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 6e99f14d..1cb65b1c 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -176,23 +176,27 @@ class SimpleRouter(BaseRouter):              if isinstance(route, DynamicDetailRoute):                  # Dynamic detail routes (@detail_route decorator)                  for httpmethods, methodname in detail_routes: +                    method_kwargs = getattr(viewset, methodname).kwargs +                    url_path = method_kwargs.pop("url_path", None) or methodname                      initkwargs = route.initkwargs.copy() -                    initkwargs.update(getattr(viewset, methodname).kwargs) +                    initkwargs.update(method_kwargs)                      ret.append(Route( -                        url=replace_methodname(route.url, methodname), +                        url=replace_methodname(route.url, url_path),                          mapping=dict((httpmethod, methodname) for httpmethod in httpmethods), -                        name=replace_methodname(route.name, methodname), +                        name=replace_methodname(route.name, url_path),                          initkwargs=initkwargs,                      ))              elif isinstance(route, DynamicListRoute):                  # Dynamic list routes (@list_route decorator)                  for httpmethods, methodname in list_routes: +                    method_kwargs = getattr(viewset, methodname).kwargs +                    url_path = method_kwargs.pop("url_path", None) or methodname                      initkwargs = route.initkwargs.copy() -                    initkwargs.update(getattr(viewset, methodname).kwargs) +                    initkwargs.update(method_kwargs)                      ret.append(Route( -                        url=replace_methodname(route.url, methodname), +                        url=replace_methodname(route.url, url_path),                          mapping=dict((httpmethod, methodname) for httpmethod in httpmethods), -                        name=replace_methodname(route.name, methodname), +                        name=replace_methodname(route.name, url_path),                          initkwargs=initkwargs,                      ))              else:  | 
