def add_comment(request): if not request.user.is_authenticated(): return HttpResponse('{"status":"fail","msg":"用户未登录"}',content_type='application/json') article_id=request.POST.get('article_id',0) comment=request.POST.get('comment','') if article_id > 0 and comment: article_comment=CommentModel() article=ArticleModel.objects.get(id=int(article_id)) article_comment.article=article article_comment.comment=comment article_comment.user=request.user article_comment.save() return HttpResponse('{"status":"success","msg":"添加成功"}',content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"添加失败"}',content_type='application/json')
def comment(event_id, message): """ Comments an event Paramters --------- event_id: the id of the event to comment message: the comment gived to the event """ com = CommentModel(event_id, message) try: com.save() return "Your comment is saved." except: return "No event with the id {} founded".format(event_id)