示例#1
0
def add(request):
    if request.method == 'POST':
        board = Board()

        board.name = request.session['authuser']['name']
        board.title = request.POST['title']
        board.content = request.POST['content']
        board_list = Board.objects.all()
        board.no = len(board_list) + 1

        g_no = Board.objects.aggregate(Max('group_no'))
        if (g_no['group_no__max'] == None):
            board.group_no = 1
        else:
            board.group_no = g_no['group_no__max'] + 1
        board.order_no = 1
        board.depth = 0

        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/')