def modify_comment(self, request, id, comment_id): logger.info('updating of comment') if request.user.role == "Admin": return Response({}, status=status.HTTP_400_BAD_REQUEST) serializer = CommentSerializer(instance=Comment.objects.get(id=comment_id, user=request.user, journal_id=id), data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_200_OK)
def write_comment(self, request, id): logger.info('post method of a comment') if request.user.role == "Admin": return Response({}, status=status.HTTP_400_BAD_REQUEST) serializer = CommentSerializer(data=request.data, context={"user": request.user, "journal": Book.objects.get(id=id)}) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def post(self, request, post_id, format=None): post = get_object_or_404(Post, id=post_id) request_data = request.data request_data['post'] = post.id serializer = CommentSerializer(data=request_data) # print(serializer.post) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)