@@ -128,13 +128,13 @@ def format_value(value, format_type=None):
128
128
return value
129
129
130
130
131
- def build_json_resource_obj (fields , resource , resource_name ):
131
+ def build_json_resource_obj (fields , resource , resource_instance , resource_name ):
132
132
resource_data = [
133
133
('type' , resource_name ),
134
134
('id' , extract_id (fields , resource )),
135
135
('attributes' , extract_attributes (fields , resource )),
136
136
]
137
- relationships = extract_relationships (fields , resource )
137
+ relationships = extract_relationships (fields , resource , resource_instance )
138
138
if relationships :
139
139
resource_data .append (('relationships' , relationships ))
140
140
# Add 'self' link if field is present and valid
@@ -166,18 +166,6 @@ def get_related_resource_type(relation):
166
166
return inflection .pluralize (relation_model .__name__ ).lower ()
167
167
168
168
169
- def get_current_instance (fields , resource ):
170
- serializer_instance = fields .serializer .instance
171
- if isinstance (serializer_instance , list ):
172
- current_id = extract_id (fields , resource )
173
- for instance in serializer_instance :
174
- # Search for our own instance
175
- if encoding .force_text (instance .pk ) == current_id :
176
- return instance
177
- else :
178
- return serializer_instance
179
-
180
-
181
169
def extract_id_from_url (url ):
182
170
http_prefix = url .startswith (('http:' , 'https:' ))
183
171
if http_prefix :
@@ -215,7 +203,7 @@ def extract_attributes(fields, resource):
215
203
return format_keys (data )
216
204
217
205
218
- def extract_relationships (fields , resource ):
206
+ def extract_relationships (fields , resource , resource_instance ):
219
207
data = OrderedDict ()
220
208
for field_name , field in six .iteritems (fields ):
221
209
# Skip URL field
@@ -230,7 +218,7 @@ def extract_relationships(fields, resource):
230
218
# special case for HyperlinkedRouterField
231
219
relation_data = list ()
232
220
relation_type = get_related_resource_type (field )
233
- related = getattr (get_current_instance ( fields , resource ) , field_name ).all ()
221
+ related = getattr (resource_instance , field_name ).all ()
234
222
for relation in related :
235
223
relation_data .append (OrderedDict ([('type' , relation_type ), ('id' , relation .pk )]))
236
224
0 commit comments