diff --git a/rest_framework/compat.py b/rest_framework/compat.py index fdf12448a..5649370ea 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -79,6 +79,12 @@ except ImportError: from collections import UserDict from collections import MutableMapping as DictMixin +# Mapping is new in python 2.6 +try: + from collections import Mapping +except ImportError: + Mapping = dict + # Try to import PIL in either of the two ways it can end up installed. try: from PIL import Image diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 6caae9242..36782e163 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -24,7 +24,7 @@ from django.utils.datastructures import SortedDict from rest_framework import ISO_8601 from rest_framework.compat import ( timezone, parse_date, parse_datetime, parse_time, BytesIO, six, smart_text, - force_text, is_non_str_iterable + force_text, is_non_str_iterable, Mapping ) from rest_framework.settings import api_settings @@ -50,7 +50,7 @@ def get_component(obj, attr_name): Given an object, and an attribute name, return that attribute on the object. """ - if isinstance(obj, dict): + if isinstance(obj, Mapping): val = obj.get(attr_name) else: val = getattr(obj, attr_name)