diff options
| author | Tom Christie | 2014-09-25 13:37:26 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-09-25 13:37:26 +0100 | 
| commit | 417fe1b675bd1d42518fb89a6f81547caef5b735 (patch) | |
| tree | de79fa6de383fd28f551b6e9e88d7a4a5859672d /rest_framework/fields.py | |
| parent | 3a5335f09f58439f8e3c0bddbed8e4c7eeb32482 (diff) | |
| download | django-rest-framework-417fe1b675bd1d42518fb89a6f81547caef5b735.tar.bz2 | |
Partial support
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 35 | 
1 files changed, 25 insertions, 10 deletions
| diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 7beccbb7..032bfd04 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -109,8 +109,7 @@ class Field(object):      def __init__(self, read_only=False, write_only=False,                   required=None, default=empty, initial=None, source=None,                   label=None, help_text=None, style=None, -                 error_messages=None, validators=[], allow_null=False, -                 context=None): +                 error_messages=None, validators=[], allow_null=False):          self._creation_counter = Field._creation_counter          Field._creation_counter += 1 @@ -139,7 +138,6 @@ class Field(object):          # These are set up by `.bind()` when the field is added to a serializer.          self.field_name = None          self.parent = None -        self._context = {} if (context is None) else context          # Collect default error message from self and parent classes          messages = {} @@ -163,13 +161,6 @@ class Field(object):          kwargs = copy.deepcopy(self._kwargs)          return self.__class__(*args, **kwargs) -    @property -    def context(self): -        root = self -        while root.parent is not None: -            root = root.parent -        return root._context -      def bind(self, field_name, parent):          """          Setup the context for the field instance. @@ -254,6 +245,8 @@ class Field(object):          """          if data is empty:              if self.required: +                if getattr(self.root, 'partial', False): +                    raise SkipField()                  self.fail('required')              return self.get_default() @@ -304,7 +297,29 @@ class Field(object):              raise AssertionError(msg)          raise ValidationError(msg.format(**kwargs)) +    @property +    def root(self): +        """ +        Returns the top-level serializer for this field. +        """ +        root = self +        while root.parent is not None: +            root = root.parent +        return root + +    @property +    def context(self): +        """ +        Returns the context as passed to the root serializer on initialization. +        """ +        return getattr(self.root, '_context', {}) +      def __repr__(self): +        """ +        Fields are represented using their initial calling arguments. +        This allows us to create descriptive representations for serializer +        instances that show all the declared fields on the serializer. +        """          return representation.field_repr(self) | 
