def add_comment(request): check = _check_post_request(request, ['comment', 'post_id']) if check[0]: new_comment = Comment() new_comment.poster = request.user new_comment.text = request.POST['comment'] try: post = Post.objects.get(pk=request.POST['post_id']) new_comment.post = post except Post.DoesNotExist: return HttpResponseBadRequest("There is no Post with id {}".format(request.POST['post_id'])) new_comment.save() return HttpResponseRedirect(reverse('social:home')) else: return HttpResponseBadRequest(check[1])
def add_comment(request): check = _check_post_request(request, ['comment', 'post_id']) if check[0]: new_comment = Comment() new_comment.poster = request.user new_comment.text = request.POST['comment'] try: post = Post.objects.get(pk=request.POST['post_id']) new_comment.post = post except Post.DoesNotExist: return HttpResponseBadRequest("There is no Post with id {}".format( request.POST['post_id'])) new_comment.save() return HttpResponseRedirect(reverse('social:home')) else: return HttpResponseBadRequest(check[1])