@@ -83,26 +83,27 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
8383
8484 json_api_included = list ()
8585
86- if view and hasattr (view , 'action' ) and view .action == 'list' :
86+ if data and 'results' in data :
87+ serializer_data = data ["results" ]
88+ else :
89+ serializer_data = data
90+
91+ if hasattr (serializer_data , 'serializer' ) and getattr (serializer_data .serializer , 'many' , False ):
8792 # The below is not true for non-paginated responses
8893 # and isinstance(data, dict):
8994
9095 # If detail view then json api spec expects dict, otherwise a list
9196 # - http://jsonapi.org/format/#document-top-level
9297 # The `results` key may be missing if unpaginated or an OPTIONS request
93- if 'results' in data :
94- resources = data ["results" ]
95- else :
96- resources = data
9798
98- resource_serializer = resources .serializer
99+ resource_serializer = serializer_data .serializer
99100
100101 # Get the serializer fields
101102 fields = utils .get_serializer_fields (resource_serializer )
102103
103104 json_api_data = list ()
104- for position in range (len (resources )):
105- resource = resources [position ] # Get current resource
105+ for position in range (len (serializer_data )):
106+ resource = serializer_data [position ] # Get current resource
106107 resource_instance = resource_serializer .instance [position ] # Get current instance
107108 json_api_data .append (
108109 utils .build_json_resource_obj (fields , resource , resource_instance , resource_name ))
0 commit comments