Django rest framewor...

alexandr_lebedev

python (django rest framework)

django rest framework example:
другие самплы
views.py
serializers.py
urls.py
class CreateDestroyAPIView(mixins.CreateModelMixin, mixins.DestroyModelMixin, GenericAPIView):
    """
    Concrete view for creation or deleting a model instance.
    """
    def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)

    def delete(self, request, *args, **kwargs):
        return self.destroy(request, *args, **kwargs)


class AuthApiMixin:
    permission_classes = (IsAuthenticated,)
    authentication_classes = (
        GraphQLJWTAuthentication,
        # CsrfExemptSessionAuthentication,
        # SessionAuthentication,
        # TokenAuthentication
    )


class LikeApiView(CreateDestroyAPIView, AuthApiMixin):

    serializer_class = LikeSerializer

    def create(self, request, *args, **kwargs):
        request.data['author'] = request.user.id
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)

    def destroy(self, request, *args, **kwargs):
        instance = Like.objects.filter(target_id=kwargs.get('pk'))
        # instance = self.get_object()
        self.perform_destroy(instance)
        return Response(status=status.HTTP_204_NO_CONTENT)
Новый листинг
скачать через терминал: wget https://coding-style.ru/code_reviews/download/84 && mkdir "django rest framewor..." && unzip 84 -d ./"django rest framewor..." && rm 84 && cd "django rest framewor..."" && git init
(ваш голос учтен)

Прикрепить файл