def second_menu_edit(request, pk): ''' 编辑二级菜单 :param request: :param pk: :return: ''' permission_obj = models.Permission.objects.filter(pid=pk).first() if not permission_obj: return HttpResponse('菜单不存在!') if request.method == 'GET': form = menu.SecondMenuModelForm(instance=permission_obj) return render(request, 'rbac/role_change.html', {'form': form}) form = menu.SecondMenuModelForm(instance=permission_obj, data=request.POST) if form.is_valid(): form.save() return redirect(urls.memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/role_change.html', {'form': form})
def second_menu_add(request, pk): """ 二级菜单添加 :param request: :param mid: 一级菜单id :return: """ if request.method == 'GET': menu_object = models.Menu.objects.filter(id=pk).first() form = menu.SecondMenuModelForm(initial={'menu': menu_object}) return render(request, 'rbac/change.html', {'form': form}) form = menu.SecondMenuModelForm(request.POST) if form.is_valid(): form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/change.html', {'form': form})
def second_menu_edit(request, pk): """ 二级菜单编辑 :param request: :param id: 一级菜单id :return: """ obj = models.Permission.objects.filter(id=pk).first() if not obj: return HttpResponse('菜单不存在') if request.method == 'GET': form = menu.SecondMenuModelForm(instance=obj) return render(request, 'rbac/change.html', {'form': form}) form = menu.SecondMenuModelForm(instance=obj, data=request.POST) if form.is_valid(): form.save() return redirect(memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/change.html', {'form': form})
def second_menu_add(request, menu_id): ''' 新增二级菜单 :param request: :param menu_id: :return: ''' menu_obj = models.Menu.objects.filter(mid=menu_id).first() if request.method == 'GET': form = menu.SecondMenuModelForm(initial={'menu': menu_obj}) return render(request, 'rbac/role_change.html', {'form': form}) form = menu.SecondMenuModelForm(request.POST) if form.is_valid(): form.save() return redirect(urls.memory_reverse(request, 'rbac:menu_list')) return render(request, 'rbac/role_change.html', {'form': form})