diff --git a/drf_util/views.py b/drf_util/views.py index e27c967..8fd1107 100644 --- a/drf_util/views.py +++ b/drf_util/views.py @@ -114,7 +114,8 @@ def get_queryset(self) -> QuerySet: return queryset def get_serializer_by_action(self): - return self.serializer_by_action.get(self.action) + return self.serializer_by_action.get(self.action) or getattr(self, f'serializer_{self.action}_class') \ + if self.action in ['list', 'retrieve'] else None def get_serializer_class(self): return self.get_serializer_by_action() or super().get_serializer_class()