def add(request): board_txt = Board() board_txt.title = request.POST['title'] board_txt.content = request.POST['content'] board_txt.user_id = request.session['authuser']['id'] board_txt.hit = 0 board_txt.name = request.session['authuser']['name'] board_txt.save() return HttpResponseRedirect('/board')
def write(request): # update board set order_no = order_no + 1 # where group_no = {groupNo} and order_no !=0 and depth = {depth}+1 board = Board() if request.POST['new'] == 'True': # 그냥 리스트에서 새 글 쓸떄 value = Board.objects.aggregate(max_groupno=Max('groupno')) max_groupno = 0 if value["max_groupno"] is None else value[ "max_groupno"] board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 board.groupno = max_groupno + 1 board.orderno = 0 board.depth = 0 board.user_id = request.session['authuser']['id'] else: # 답글 쓸때 value = Board.objects.filter(id=request.POST['id']) Board.objects.filter(orderno__gte=value[0].orderno + 1).update(orderno=F('orderno') + 1) board.groupno = value[0].groupno board.orderno = value[0].orderno + 1 board.depth = value[0].depth + 1 board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 board.groupno = request.POST['groupno'] board.orderno = int(request.POST['orderno']) + 1 board.depth = int(request.POST['depth']) + 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board/list')
def reply(request): #reply method 수정해야됨 value = Board.objects.aggregate(max_groupno=Max('groupno')) max_groupno = 0 if value["max_groupno"] is None else value["max_groupno"] board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 board.groupno = max_groupno + 1 board.orderno = 1 board.depth = 1 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board/list')
def write(request): if request.method == "GET": return render(request, 'board/write.html') if request.method == "POST": board = Board() board.title = request.POST['title'] board.contents = request.POST['contents'] board.hit = request.POST['hit'] board.group_no = request.POST['group_no'] board.order_no = request.POST['order_no'] board.depth = request.POST['depth'] board.no = User.objects.get(no=request.session['authuser']['no']) if board.group_no == '': maxgroupno = Board.objects.aggregate(Max('group_no')) board.group_no = maxgroupno['group_no__max'] + 1 print(board.group_no) board.save() else: board.save() return HttpResponseRedirect('/board/')
def write(request): result = auth(request) if result == True: return HttpResponseRedirect("/") if request.method == 'GET': return render(request, 'board/write.html') else: board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 groupno = Board.objects.aggregate(max_groupno=Max('groupno') + 1) if groupno['max_groupno'] is None: groupno['max_groupno'] = 1 board.groupno = groupno['max_groupno'] board.orderno = 1 board.depth = 0 board.user_id = request.session['authuser']['id'] board.save() return HttpResponseRedirect('/board/list/')
def reply(request, id): result = auth(request) if result == True: return HttpResponseRedirect("/") if request.method == 'GET': data = {'id': id} return render(request, 'board/replyform.html', data) else: board = Board() board.title = request.POST['title'] board.content = request.POST['content'] board.hit = 0 parent_board = Board.objects.get(id=id) board.groupno = parent_board.groupno board.orderno = parent_board.orderno + 1 board.depth = parent_board.depth + 1 board.user_id = request.session['authuser']['id'] Board.objects.filter(groupno=board.groupno).filter( orderno__gte=board.orderno).update(orderno=F('orderno') + 1) board.save() return HttpResponseRedirect('/board/list/')