Ка можно переписать данный функциональный view в стиле generic CBV
# Like comment
@api_view(['PUT'])
@authentication_classes([SessionAuthentication, BasicAuthentication])
@permission_classes([IsAuthenticated])
def like_comment_api(request, story_id, comment_id):
if request.method == 'PUT':
author = request.user
story = Story.objects.get(pk=story_id)
comment = story.comments.get(pk=comment_id)
like = CommentLike.objects.filter(author=author, comment=comment).exists()
if like is False:
comment_like = CommentLikeSerializer(data=request.data)
if comment_like.is_valid():
comment_like.save(author=author, comment=comment)
return Response(comment_like.data, status=201)
return Response(comment_like.data, status=203)
comment_like = CommentLike.objects.get(author=author, comment=comment)
comment_like.delete()
return Response(status=202)