@@ -131,7 +131,7 @@ def format_value(value, format_type=None):
131
131
def build_json_resource_obj (fields , resource , resource_instance , resource_name ):
132
132
resource_data = [
133
133
('type' , resource_name ),
134
- ('id' , resource_instance .pk ),
134
+ ('id' , encoding . force_text ( resource_instance .pk ) ),
135
135
('attributes' , extract_attributes (fields , resource )),
136
136
]
137
137
relationships = extract_relationships (fields , resource , resource_instance )
@@ -212,7 +212,7 @@ def extract_relationships(fields, resource, resource_instance):
212
212
relation_type = get_related_resource_type (field )
213
213
related = getattr (resource_instance , field_name ).all ()
214
214
for relation in related :
215
- relation_data .append (OrderedDict ([('type' , relation_type ), ('id' , relation .pk )]))
215
+ relation_data .append (OrderedDict ([('type' , relation_type ), ('id' , encoding . force_text ( relation .pk ) )]))
216
216
217
217
data .update ({field_name : {
218
218
'links' : {
@@ -239,7 +239,7 @@ def extract_relationships(fields, resource, resource_instance):
239
239
{
240
240
field_name : {
241
241
'data' : (OrderedDict ([
242
- ('type' , relation_type ), ('id' , relation_id )
242
+ ('type' , relation_type ), ('id' , encoding . force_text ( relation_id ) )
243
243
]) if relation_id is not None else None )
244
244
}
245
245
}
@@ -281,7 +281,7 @@ def extract_relationships(fields, resource, resource_instance):
281
281
nested_resource_instance = resource_instance_manager [position ]
282
282
relation_data .append (
283
283
OrderedDict ([
284
- ('type' , relation_type ), ('id' , nested_resource_instance .pk )
284
+ ('type' , relation_type ), ('id' , encoding . force_text ( nested_resource_instance .pk ) )
285
285
]))
286
286
287
287
data .update ({field_name : {'data' : relation_data }})
@@ -296,7 +296,7 @@ def extract_relationships(fields, resource, resource_instance):
296
296
'data' : (
297
297
OrderedDict ([
298
298
('type' , relation_type ),
299
- ('id' , getattr (resource_instance , field_name ).pk )
299
+ ('id' , encoding . force_text ( getattr (resource_instance , field_name ).pk ) )
300
300
]) if resource .get (field_name ) else None )
301
301
}
302
302
})
0 commit comments