diff options
| author | Tom Christie | 2014-12-10 09:16:01 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-12-10 09:16:01 +0000 | 
| commit | 81d0b748b400263114422c464f75357e24952ad6 (patch) | |
| tree | 269c81d1ed4f5f491624b6f107eee8fa827621b4 /rest_framework | |
| parent | 76956beab41cda7abdfb0aac714b35494f6ca3d5 (diff) | |
| download | django-rest-framework-81d0b748b400263114422c464f75357e24952ad6.tar.bz2 | |
Improve field lookup behavior for dicts/mappings. Closes #2244. Closes #2243.
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/fields.py | 11 | 
1 files changed, 5 insertions, 6 deletions
| diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 99498da7..15e59861 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -15,6 +15,7 @@ from rest_framework.compat import (  from rest_framework.exceptions import ValidationError  from rest_framework.settings import api_settings  from rest_framework.utils import html, representation, humanize_datetime +import collections  import copy  import datetime  import decimal @@ -60,14 +61,12 @@ def get_attribute(instance, attrs):              # Break out early if we get `None` at any point in a nested lookup.              return None          try: -            instance = getattr(instance, attr) +            if isinstance(instance, collections.Mapping): +                instance = instance[attr] +            else: +                instance = getattr(instance, attr)          except ObjectDoesNotExist:              return None -        except AttributeError as exc: -            try: -                return instance[attr] -            except (KeyError, TypeError, AttributeError): -                raise exc          if is_simple_callable(instance):              instance = instance()      return instance | 
