Beispiel #1
0
def add_comment(request):
    if request.method == 'POST':
        if 'comment' not in request.POST:
            return HttpResponse(status=400)

        if 'article' not in request.POST:
            return HttpResponse(status=400)

        user = request.user
        author = user
        comment = request.POST['comment']
        article_pk = int(request.POST['article'])

        comment_obj = Comment()
        comment_obj.author = author
        comment_obj.comment = comment
        comment_obj.article = News.objects.get(pk=article_pk)
        comment_obj.save()

    return HttpResponse(user.first_name + user.last_name, status=200)