diff --git a/backend/apps/comment/api/v1/serializers.py b/backend/apps/comment/api/v1/serializers.py index 231830b..c0b9baf 100644 --- a/backend/apps/comment/api/v1/serializers.py +++ b/backend/apps/comment/api/v1/serializers.py @@ -29,6 +29,5 @@ def create(self, validated_data): comment_instance: CommentModel = CommentModel.objects.create_child( **data ) # pyright: ignore - comment_instance.save() return comment_instance diff --git a/backend/apps/comment/api/v1/viewsets.py b/backend/apps/comment/api/v1/viewsets.py index f51bd9b..381f823 100644 --- a/backend/apps/comment/api/v1/viewsets.py +++ b/backend/apps/comment/api/v1/viewsets.py @@ -1,10 +1,10 @@ -from rest_framework import viewsets +from common.api.bases.viewsets import UpdateRetrieveDestroyViewSet from ...models import CommentModel from .serializers import CommentSerializer -class CommentModelViewSet(viewsets.ModelViewSet): +class CommentModelViewSet(UpdateRetrieveDestroyViewSet): queryset = CommentModel.objects.all() serializer_class = CommentSerializer diff --git a/backend/common/api/bases/__init__.py b/backend/common/api/bases/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/common/api/bases/viewsets.py b/backend/common/api/bases/viewsets.py new file mode 100644 index 0000000..0905106 --- /dev/null +++ b/backend/common/api/bases/viewsets.py @@ -0,0 +1,17 @@ +from rest_framework import mixins, viewsets + + +class UpdateRetrieveDestroyViewSet( + mixins.UpdateModelMixin, + mixins.RetrieveModelMixin, + mixins.DestroyModelMixin, + viewsets.GenericViewSet, +): + """ + A viewset that provides `update`, `retrieve`, and `destroy` actions. + + To use it, override the class and set the `.queryset` and + `.serializer_class` attributes. + """ + + pass