mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
This commit is contained in:
parent
76956beab4
commit
81d0b748b4
|
@ -15,6 +15,7 @@ from rest_framework.compat import (
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.utils import html, representation, humanize_datetime
|
from rest_framework.utils import html, representation, humanize_datetime
|
||||||
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
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.
|
# Break out early if we get `None` at any point in a nested lookup.
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
instance = getattr(instance, attr)
|
if isinstance(instance, collections.Mapping):
|
||||||
|
instance = instance[attr]
|
||||||
|
else:
|
||||||
|
instance = getattr(instance, attr)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return None
|
return None
|
||||||
except AttributeError as exc:
|
|
||||||
try:
|
|
||||||
return instance[attr]
|
|
||||||
except (KeyError, TypeError, AttributeError):
|
|
||||||
raise exc
|
|
||||||
if is_simple_callable(instance):
|
if is_simple_callable(instance):
|
||||||
instance = instance()
|
instance = instance()
|
||||||
return instance
|
return instance
|
||||||
|
|
Loading…
Reference in New Issue
Block a user