Skip to content

Commit 5c4cb88

Browse files
committed
Use correct serializer for rendering
Ensure that the correct resource is returned during rendering, which in turn requires to use the correct serializer, depending on if it is a related resource or the parent resource. sliverc pointed out the issue here.
1 parent a2b5704 commit 5c4cb88

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rest_framework_json_api/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ def get_resource_name(context, expand_polymorphic_types=False):
5252
resource_name = getattr(view, 'resource_name')
5353
except AttributeError:
5454
try:
55-
serializer = view.get_serializer_class()
55+
if 'kwargs' in context and 'related_field' in context['kwargs']:
56+
serializer = view.get_related_serializer_class()
57+
else:
58+
serializer = view.get_serializer_class()
5659
if expand_polymorphic_types and issubclass(serializer, PolymorphicModelSerializer):
5760
return serializer.get_polymorphic_types()
5861
else:

0 commit comments

Comments
 (0)