Skip to content

Commit 3f99c29

Browse files
committed
Adapt Nested view to use new response serializer support
This also changes the behavior for a more consistent one: if a detail_serializer_class is defined, this is the one used to build the response
1 parent e6d3df3 commit 3f99c29

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

drf_kit/views/single_nested_viewsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def list(self, request, **kwargs):
5656
obj = self.get_object()
5757
if obj is None:
5858
raise Http404()
59-
serializer = self.get_serializer(instance=obj)
59+
serializer = self.get_response_serializer(obj)
6060
return Response(data=serializer.data, status=status.HTTP_200_OK)
6161

6262
def patch(self, request, *args, **kwargs):

test_app/tests/tests_views/tests_nested_views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ def test_list_endpoint(self):
2626
self.assertEqual(2, len(data['results']))
2727

2828
expected_data = [
29-
self.expected_wizards[1],
30-
self.expected_wizards[0],
29+
self.expected_detailed_wizards[1],
30+
self.expected_detailed_wizards[0],
3131
]
32+
expected_data[1]['house'] = self.expected_houses[0]
33+
expected_data[0]['house'] = self.expected_houses[0]
34+
3235
self.assertEqual(expected_data, data['results'])
3336

3437
def test_detail_endpoint(self):

test_app/tests/tests_views/tests_very_custom_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_list_endpoint(self):
2020
data = response.json()
2121
self.assertEqual(4, len(data['results']))
2222

23-
expected = list(reversed(self.expected_wizards))
23+
expected = list(reversed(self.expected_detailed_wizards))
2424
self.assertEqual(expected, data['results'])
2525

2626
def test_detail_endpoint_out_of_queryset(self):

0 commit comments

Comments
 (0)