diff options
| author | Tom Christie | 2014-12-15 12:18:55 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-12-15 12:18:55 +0000 | 
| commit | b6ee784240b3c7f6cd62af5b6fe6d1014d7bf6d4 (patch) | |
| tree | e3cdb5a6e210e5ba26d6726cc08a44c8f450776b /rest_framework/fields.py | |
| parent | 8934e61b67e4aed38b04f2fe18f011ecbf9010cb (diff) | |
| parent | af53e34dd5873f3373e9991c3825e70d92432e14 (diff) | |
| download | django-rest-framework-b6ee784240b3c7f6cd62af5b6fe6d1014d7bf6d4.tar.bz2 | |
Merge master
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 26 | 
1 files changed, 20 insertions, 6 deletions
| diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 205efd2f..f3e17b18 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals  from django.conf import settings  from django.core.exceptions import ObjectDoesNotExist  from django.core.exceptions import ValidationError as DjangoValidationError @@ -10,7 +11,8 @@ from django.utils.translation import ugettext_lazy as _  from rest_framework import ISO_8601  from rest_framework.compat import (      EmailValidator, MinValueValidator, MaxValueValidator, -    MinLengthValidator, MaxLengthValidator, URLValidator, OrderedDict +    MinLengthValidator, MaxLengthValidator, URLValidator, OrderedDict, +    unicode_repr, unicode_to_repr  )  from rest_framework.exceptions import ValidationError  from rest_framework.settings import api_settings @@ -113,7 +115,9 @@ class CreateOnlyDefault:          return self.default      def __repr__(self): -        return '%s(%s)' % (self.__class__.__name__, repr(self.default)) +        return unicode_to_repr( +            '%s(%s)' % (self.__class__.__name__, unicode_repr(self.default)) +        )  class CurrentUserDefault: @@ -124,7 +128,7 @@ class CurrentUserDefault:          return self.user      def __repr__(self): -        return '%s()' % self.__class__.__name__ +        return unicode_to_repr('%s()' % self.__class__.__name__)  class SkipField(Exception): @@ -382,13 +386,23 @@ class Field(object):          """          Transform the *incoming* primitive data into a native value.          """ -        raise NotImplementedError('to_internal_value() must be implemented.') +        raise NotImplementedError( +            '{cls}.to_internal_value() must be implemented.'.format( +                cls=self.__class__.__name__ +            ) +        )      def to_representation(self, value):          """          Transform the *outgoing* native value into primitive data.          """ -        raise NotImplementedError('to_representation() must be implemented.') +        raise NotImplementedError( +            '{cls}.to_representation() must be implemented.\n' +            'If you are upgrading from REST framework version 2 ' +            'you might want `ReadOnlyField`.'.format( +                cls=self.__class__.__name__ +            ) +        )      def fail(self, key, **kwargs):          """ @@ -453,7 +467,7 @@ class Field(object):          This allows us to create descriptive representations for serializer          instances that show all the declared fields on the serializer.          """ -        return representation.field_repr(self) +        return unicode_to_repr(representation.field_repr(self))  # Boolean types... | 
