def addComment(request): comment_text = request.POST.get('comment_text') post_pk = request.POST.get('post_pk') post = Post.objects.get(pk=post_pk) commenter_info = {} try: comment = Comment(comment=comment_text, user=request.user, post=post) comment.save() username = request.user.username commenter_info = { 'username': username, 'comment_text': comment_text } result = 1 except Exception as e: print(e) result = 0 return { 'result': result, 'post_pk': post_pk, 'commenter_info': commenter_info }
def addComment(request): '''come from index.js in static/js''' post_pk = request.POST.get('post_pk') post = Post.objects.get(pk=post_pk) comment_text = request.POST.get('comment_text') commenter_info = {} try: comment = Comment(post=post, user=request.user, comment=comment_text) comment.save( ) # might throws Exception if there is already a like with the same post and user result = 1 commenter_info = { 'username': request.user.username, 'comment_text': comment_text } except Exception as e: print(e) result = 0 return { 'result': result, 'post_pk': post_pk, 'commenter_info': commenter_info }
def addComment(request): comment_text = request.POST.get('comment_text') post_pk = request.POST.get('post_pk') post = Post.objects.get(pk=post_pk) comm = Comment(user=request.user, post=post, comment=comment_text) comm.save() return { 'result': 1, 'post_pk': post_pk }
def addComment(request): # comment_text and post_pk get from index.js comment_text = request.POST.get('comment_text') post_pk = request.POST.get('post_pk') post = Post.objects.get(pk=post_pk) commenter_info = {} # if this user did not comment this post before try: comment = Comment(post=post, user=request.user, comment=comment_text) comment.save() username = request.user.username commenter_info = {'username': username, 'comment_text': comment_text} result = 1 except Exception as e: print(e) result = 0 return { 'result': result, 'post_pk': post_pk, 'commenter_info': commenter_info }
def addComment(request): #拿到post_pk, comment_text是从index.js中传过来的key post_pk = request.POST.get('post_pk') comment_text = request.POST.get('comment_text') #根据post_id拿到post post = Post.objects.get(pk=post_pk) commenter_info = {} try: comment = Comment(post=post, user=request.user, comment=comment_text) comment.save() username = request.user.username commenter_info = {'username': username, 'comment_text': comment_text} result = 1 except Exception as e: print(e) result = 0 return { 'result': result, 'post_pk': post_pk, 'commenter_info': commenter_info }