@@ -83,26 +83,27 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
83
83
84
84
json_api_included = list ()
85
85
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 ):
87
92
# The below is not true for non-paginated responses
88
93
# and isinstance(data, dict):
89
94
90
95
# If detail view then json api spec expects dict, otherwise a list
91
96
# - http://jsonapi.org/format/#document-top-level
92
97
# 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
97
98
98
- resource_serializer = resources .serializer
99
+ resource_serializer = serializer_data .serializer
99
100
100
101
# Get the serializer fields
101
102
fields = utils .get_serializer_fields (resource_serializer )
102
103
103
104
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
106
107
resource_instance = resource_serializer .instance [position ] # Get current instance
107
108
json_api_data .append (
108
109
utils .build_json_resource_obj (fields , resource , resource_instance , resource_name ))
0 commit comments