def menu_edit(request, pk): ''' 编辑一级菜单 :param request: :param pk: :return: ''' menu_obj = models.Menu.objects.filter(pk=pk).first() if not menu_obj: return HttpResponse('角色不存在!') if request.method == 'GET': form = menu.MenuModelForm(instance=menu_obj) return render(request, 'rbac/role_change.html', {'form': form}) form = menu.MenuModelForm(instance=menu_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 menu_add(request): """ 添加菜单 :param request: :return: """ if request.method == 'GET': form = menu.MenuModelForm() return render(request, 'rbac/change.html', {'form': form}) form = menu.MenuModelForm(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 menu_edit(request, id): """ 编辑菜单 :param request: :param id: 对象id :return: """ obj = models.Menu.objects.filter(id=id).first() if not obj: return HttpResponse('菜单不存在') if request.method == 'GET': form = menu.MenuModelForm(instance=obj) return render(request, 'rbac/change.html', {'form': form}) form = menu.MenuModelForm(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})