views.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:sdining 作者: Lurance 项目源码 文件源码
def comment(request, opk):

    try:
        order = request.user.myorder.get(pk=opk)
        business = order.food.business
    except:
        return HttpResponseNotFound()

    if not order.is_done:
        return HttpResponseNotFound()

    if request.method == 'GET':
        return render(request, 'operation/comment.html', {
            'order': order
        })
    elif request.method == 'POST':
        trank = int(request.POST.get('trank', False))
        prank = int(request.POST.get('prank', False))
        textcomment = request.POST.get('textcomment', False)
        try:
            order.trank, order.prank = trank, prank
            average = (trank + prank) / 2
            order.is_comment = True
            order.save()
            if textcomment:
                BusinessTextComment.objects.create(business=order.food.business, comment=textcomment)
            num_order = Order.objects.filter(is_comment=True).count()
            business.total_rank = business.total_rank + average
            business.rank = round(business.total_rank / num_order)
            business.save()
            return JsonResponse({'status': 1})
        except Exception as e:
            print(e)
            return JsonResponse({'status': 0})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号