mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
__getitem__ to check for container-like objects
This commit is contained in:
parent
4762455af3
commit
467bc56e08
|
@ -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, Mapping
|
||||
force_text, is_non_str_iterable
|
||||
)
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
|
@ -50,8 +50,8 @@ def get_component(obj, attr_name):
|
|||
Given an object, and an attribute name,
|
||||
return that attribute on the object.
|
||||
"""
|
||||
if isinstance(obj, Mapping):
|
||||
val = obj.get(attr_name)
|
||||
if hasattr(obj, '__getitem__'):
|
||||
val = obj[attr_name]
|
||||
else:
|
||||
val = getattr(obj, attr_name)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user