Esempio n. 1
0
def get_all_comments(request):
    try:
        blog_comment = models.Comment.objects.all()
    except:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    serialized = serializer.GetCommentSerializer(blog_comment, many=True)

    return Response({'Blog Comments': serialized.data})
Esempio n. 2
0
def get_comment(request, id):
    try:
        blog_comment = models.Comment.objects.get(id=id)
    except:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    serialized = serializer.GetCommentSerializer(blog_comment)

    return Response({'Blog Comments': serialized.data})
Esempio n. 3
0
def get_blog_details(request, id):
    try:
        post = models.Post.objects.get(id=id)
        comments = models.Comment.objects.filter(post_id=id)
    except:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    post_serialized = serializer.GetPostSerializer(post)
    comments_serialized = serializer.GetCommentSerializer(comments, many=True)
    return Response({
        'Post': post_serialized.data,
        'Comments': comments_serialized.data
    })
Esempio n. 4
0
def update_comment(request, id, cid):
    try:
        comment_update = models.Comment.objects.filter(id=cid)
        comment_update.update(body=request.data['body'])
    except:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    # Return blog post with available comments
    try:
        post = models.Post.objects.get(id=id)
        comments = models.Comment.objects.filter(post_id=id)
    except:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    post_serialized = serializer.GetPostSerializer(post)
    comments_serialized = serializer.GetCommentSerializer(comments, many=True)
    return Response({
        'Post': post_serialized.data,
        'Comments': comments_serialized.data
    })