예제 #1
0
    def post(self, request, *args, **kwargs):
        '''
        用户收藏,取消收藏
        :param request:
        :param org_id:
        :param args:
        :param kwargs:
        :return:
        '''
        comment_form = CommentsForm(request.POST)
        # 如果用户未登录
        if not request.user.is_authenticated:
            return JsonResponse({
                'status': 'fail',
                'msg': '用户未登录'
            })
        if comment_form.is_valid():
            course = comment_form.cleaned_data['course']
            comments = comment_form.cleaned_data['comments']

            comment = CourseComments()
            comment.user = request.user
            comment.comments = comments
            comment.course = course
            comment.save()
            return JsonResponse({
                'status': 'success',
            })
        else:
            return JsonResponse({
                'status': 'fail',
                'msg': '参数错误'
            })