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})
评论列表
文章目录