diff options
| author | Tom Christie | 2014-09-24 20:53:37 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-09-24 20:53:37 +0100 | 
| commit | fb1546ee50953faae8af505a0c90da00ac08ad92 (patch) | |
| tree | 8840488b273557672cba6f403f37b4f2d0630697 /rest_framework/fields.py | |
| parent | 127c0bd3d68860dd6567d81047257fbc3e70b4b9 (diff) | |
| download | django-rest-framework-fb1546ee50953faae8af505a0c90da00ac08ad92.tar.bz2 | |
Enforce field_name != source
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 11 | 
1 files changed, 11 insertions, 0 deletions
| diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 1f7d964a..9280ea3a 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -160,6 +160,17 @@ class Field(object):          """          Setup the context for the field instance.          """ + +        # In order to enforce a consistent style, we error if a redundant +        # 'source' argument has been used. For example: +        # my_field = serializer.CharField(source='my_field') +        assert self._kwargs.get('source') != field_name, ( +            "It is redundant to specify `source='%s'` on field '%s' in " +            "serializer '%s', as it is the same the field name. " +            "Remove the `source` keyword argument." % +            (field_name, self.__class__.__name__, parent.__class__.__name__) +        ) +          self.field_name = field_name          self.parent = parent          self.root = root | 
