22Utils.
33"""
44import copy
5+ import inspect
56import warnings
67from collections import OrderedDict
7- import inspect
88
99import inflection
10+ from rest_framework import exceptions
11+ from rest_framework .exceptions import APIException
12+
1013from django .conf import settings
11- from django .utils import encoding
12- from django .utils import six
14+ from django .db . models import Manager
15+ from django .utils import encoding , six
1316from django .utils .module_loading import import_string as import_class_from_dotted_path
1417from django .utils .translation import ugettext_lazy as _
15- from django .db .models import Manager
16- from rest_framework .exceptions import APIException
17- from rest_framework import exceptions
1818
1919try :
2020 from rest_framework .serializers import ManyRelatedField
@@ -87,6 +87,7 @@ def get_serializer_fields(serializer):
8787 pass
8888 return fields
8989
90+
9091def format_keys (obj , format_type = None ):
9192 """
9293 Takes either a dict or list and returns it with camelized keys only if
@@ -148,6 +149,7 @@ def format_relation_name(value, format_type=None):
148149 pluralize = getattr (settings , 'JSON_API_PLURALIZE_RELATION_TYPE' , None )
149150 return format_resource_type (value , format_type , pluralize )
150151
152+
151153def format_resource_type (value , format_type = None , pluralize = None ):
152154 if format_type is None :
153155 format_type = getattr (settings , 'JSON_API_FORMAT_TYPES' , False )
@@ -184,7 +186,7 @@ def get_related_resource_type(relation):
184186 elif hasattr (parent_serializer , 'parent' ) and hasattr (parent_serializer .parent , 'Meta' ):
185187 parent_model = getattr (parent_serializer .parent .Meta , 'model' , None )
186188
187- if parent_model is not None :
189+ if parent_model is not None :
188190 if relation .source :
189191 if relation .source != '*' :
190192 parent_model_relation = getattr (parent_model , relation .source )
@@ -199,6 +201,8 @@ def get_related_resource_type(relation):
199201 except AttributeError :
200202 # Django 1.7
201203 relation_model = parent_model_relation .related .model
204+ elif hasattr (parent_model_relation , 'rel' ):
205+ relation_model = parent_model_relation .rel .related_model
202206 elif hasattr (parent_model_relation , 'field' ):
203207 try :
204208 relation_model = parent_model_relation .field .remote_field .model
0 commit comments