def edit_module(request, mid): """ 编辑模块 """ if request.method == "POST": forms = ModuleForm(request.POST) if forms.is_valid(): project = forms.cleaned_data['project'] name = forms.cleaned_data['name'] describe = forms.cleaned_data['describe'] m = Module.objects.get(id=mid) m.project = project m.name = name m.describe = describe m.save() return HttpResponseRedirect("/manage/module/") else: print('模块编辑表单数据,有误...') return HttpResponseRedirect("/manage/module/") else: if mid: m = Module.objects.get(id=mid) forms = ModuleForm(instance=m) return render(request, "module/edit.html", { "forms": forms, "mid": mid }) else: pass #跳转处理
def edit_module(request, mid): """ 编辑项目 :param request: :param mid: """ if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): project = form.cleaned_data['project'] name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] m = Module.objects.get(id=mid) m.project = project m.name = name m.describe = describe m.save() return HttpResponseRedirect("/manage/module_list/") else: if mid: m = Module.objects.get(id=mid) form = ModuleForm(instance=m) else: form = ModuleForm() return render(request, 'module/edit.html', { 'form': form, "id": mid})
def edit_module(request, mid): """ 编辑模块 :param request: :param mid: :return: """ if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): project = form.cleaned_data['project'] name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] module = Module.objects.get(id=mid) module.project = project module.name = name module.describe = describe module.save() return HttpResponseRedirect('/manage/module_list/') else: if mid: module = Module.objects.get(id=mid) form = ModuleEditForm(instance=module) else: form = ModuleForm() return render(request, "module/edit.html", {"form": form, "id": mid})
def add_module(request): if request.method == 'POST': form = ModuleForm(request.POST) if form.is_valid(): project = form.cleaned_data['project'] name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] Module.objects.create(project=project, name=name, describe=describe) return HttpResponseRedirect('/manage/module_list/') else: form = ModuleForm() return render(request, 'module/add.html/', {'form': form})
def add_module(request): """创建模块""" if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): project = form.cleaned_data['project'] name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] Module.objects.create(name=name, describe=describe, project=project) return HttpResponseRedirect("/manage/module_list/") else: form = ModuleForm() return render(request, 'module/add.html', {'form': form})
def add_module(request): """创建模块""" if request.method == "POST": form = ModuleForm(request.POST) print("-------->form:", form) if form.is_valid(): project = form.cleaned_data["project"] name = form.cleaned_data['name'] describe = form.cleaned_data["describe"] Module.objects.create(name=name, describe=describe, project=project) return HttpResponseRedirect("/app_manage/module") else: form = ModuleForm() return render(request, "module/add.html", {'form': form})
def add_module(request): #判断请求方法是否是post if request.method == "POST": #如果是post的话,就去请求这个表单 form = ModuleForm(request.POST) if form.is_valid(): project = form.cleaned_data['project'] #项目 name = form.cleaned_data['name'] #名称 describe = form.cleaned_data['describe'] # 描述 Module.objects.create(name=name, describe=describe, project=project) #进行创建数据 #创建完成之后跳转到模块列表页 return HttpResponseRedirect("/manage/module_list/") else: #如果是空的话跳转到project_add界面 form = ModuleForm() #把表单作为一个对象传给到前端 return render(request, "module/add.html", {"form": form})
def add_module(request): """ 创建模块 """ if request.method == "POST": forms = ModuleForm(request.POST) if forms.is_valid(): project = forms.cleaned_data['project'] name = forms.cleaned_data['name'] describe = forms.cleaned_data['describe'] m = Module.objects.create(project=project, name=name, describe=describe) return HttpResponseRedirect('/manage/module/') else: pass #需处理 else: forms = ModuleForm() return render(request, "module/add.html", {"forms": forms})
def add_module(request): """ 新增模块 :param request: :return: """ if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): project = form.cleaned_data['project'] name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] Module.objects.create(name=name, describe=describe, project=project) return HttpResponseRedirect('/manage/module_list/') else: form = ModuleForm() return render(request, "module/add.html", {"form": form})
def edit_module(request, mid): """编辑模块""" if request.method == "POST": # 更新数据 form = ModuleForm(request.POST) if form.is_valid(): project = form.cleaned_data["project"] name = form.cleaned_data["name"] describe = form.cleaned_data["describe"] m = Module.objects.get(id=mid) m.name = name m.describe = describe m.project = project m.save() return HttpResponseRedirect("/app_manage/module") else: if mid: module = Module.objects.get(id=mid) form = ModuleForm(instance=module) else: form = ModuleForm() return render(request, "module/edit.html", {"form": form, "id": mid})