def add_module(request): '''添加模块''' if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): name = form.cleaned_data["name"] describe = form.cleaned_data["describe"] project = form.cleaned_data["project"] Model.objects.create(name=name, describe=describe, project=project) return HttpResponseRedirect('/manage/module_manage/') else: form = ModuleForm() return render(request, "module_manage.html", {"type": "add", "form": form})
def add_module(request): if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): new_name = form.cleaned_data["name"] new_description = form.cleaned_data["description"] new_project = form.cleaned_data["project"] Module.objects.create(name=new_name, description=new_description, project=new_project) return HttpResponseRedirect("/manage/module_manage/") else: form = ModuleForm() return render(request, "module_manage.html", {"form": form, "type": "add"})
def add_module(request): if request.method == 'POST': #提交表单的post请求 form = ModuleForm(request.POST) #用ProjectForm校验表单数据 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_manage/') else: #进入表单页面的get请求 form = ModuleForm() return render(request, 'module_manage.html', {'form': form, 'type': 'add'})
def add_module_action(request): # 如果form通过POST方法发送数据 if request.method == 'POST': # 接受request.POST参数构造form类的实例 form = ModuleForm(request.POST) # 验证数据是否合法 if form.is_valid(): name = form.cleaned_data["name"] describe = form.cleaned_data["describe"] # create_time = form.cleaned_data["create_time"] project = form.cleaned_data["project"] module = Module(name=name, describe=describe, project=project) module.save() return HttpResponseRedirect('/manage/module_manage/') # 如果是通过GET方法请求数据,返回一个空的表单 else: form = ModuleForm() return render(request, 'project_app/module_manage.html', {'type': 'add', 'form': form})
def edit_module(request, mid): if request.method == 'POST': form = ModuleForm(request.POST) if form.is_valid(): model = Module.objects.get(id=mid) model.name = form.cleaned_data['name'] model.describe = form.cleaned_data['describe'] model.project = form.cleaned_data['project'] model.save() return HttpResponseRedirect('/manage/module_manage/') else: if mid: form = ModuleForm(instance=Module.objects.get(id=mid)) return render(request, 'module_manage.html', { 'form': form, 'type': 'edit', })
def edit_module(request, mid): """编辑项目""" if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): model = Module.objects.get(id=mid) model.name = form.cleaned_data['name'] model.describe = form.cleaned_data['describe'] model.project = form.cleaned_data['project'] model.save() return HttpResponseRedirect("/manage/module_manage/") else: if mid: form = ModuleForm(instance=Module.objects.get(id=mid)) context = { "form": form, "type": "edit", } return render(request, "module_manage.html", context=context)
def add_module(request): """添加模块""" if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] project = form.cleaned_data['project'] Module.objects.create(name=name, describe=describe, project=project) return HttpResponseRedirect("/manage/module_manage/") else: form = ModuleForm() context = { "form": form, "type": "add", } return render(request, "module_manage.html", context=context)
def add_module(request): if request.method == 'POST': form = ModuleForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] project = form.cleaned_data['project'] Module.objects.create(name=name, describe=describe, project=project) return HttpResponseRedirect('/manage/module_manage/') else: form = ModuleForm() return render(request, 'module_manage.html', { 'form': form, "type": "add", })
def edit_module(request, mid): if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): new_name = form.cleaned_data["name"] new_description = form.cleaned_data["description"] new_project = form.cleaned_data["project"] Module.objects.select_for_update().filter(id=mid).update( name=new_name, description=new_description, project=new_project) return HttpResponseRedirect("/manage/module_manage/") else: if mid: form = ModuleForm(instance=Module.objects.get(id=mid)) return render(request, "module_manage.html", { "form": form, "mid": mid, "type": "edit" })
def edit_module(request, module_id): print("编辑模块的id:", module_id) if request.method == 'POST': # print(request.POST.get("project")) # print(request.POST.get("name")) # print(request.POST.get("describe")) # 接受request.POST参数构造form类的实例 form = ModuleForm(request.POST) if form.is_valid(): # 数据库查询数据 module = Module.objects.get(id=module_id) # 更新数据 module.name = form.cleaned_data['name'] module.describe = form.cleaned_data["describe"] module.project = form.cleaned_data["project"] # 保存 module.save() return HttpResponseRedirect('/manage/module_manage/') else: module = Module.objects.get(id=module_id) form = ModuleForm(instance=module) return render(request, "project_app/module_manage.html",{'type': 'edit', 'form': form})
def add_module(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = ModuleForm(request.POST) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] project=form.cleaned_data['project'] Module.objects.create(name=name,describe=describe,project=project) # redirect to a new URL: return HttpResponseRedirect('/manage/module_manage/') # if a GET (or any other method) we'll create a blank form else: form = ModuleForm() return render(request, 'module_manage.html', {'type':'add', 'form': form})
def project_module_update(request, module_id): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = ModuleForm(request.POST) # check whether it's valid: if form.is_valid(): model = Module.objects.get(id=module_id) model.name = form.cleaned_data['name'] model.describe = form.cleaned_data['describe'] model.project = form.cleaned_data['project'] model.save() return HttpResponseRedirect('/project/project_module/') else: if module_id: form = ModuleForm(instance=Module.objects.get(id=module_id)) return render(request, 'project_module/project_module.html', { 'form': form, 'type': 'update', 'module_id': module_id })
def project_module_create(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = ModuleForm(request.POST) # check whether it's valid: if form.is_valid(): name = form.cleaned_data['name'] describe = form.cleaned_data['describe'] project = form.cleaned_data['project'] Module.objects.create(name=name, describe=describe, project=project) return HttpResponseRedirect('/project/project_module/') else: form = ModuleForm() return render(request, 'project_module/project_module.html', { 'form': form, 'type': 'create' })
def edit_module(request, mid): """ 编辑模块 :param request: :param mid: :return: """ if request.method == 'POST': form = ModuleForm(request.POST) if form.is_valid(): module = Module.objects.get(id=mid) module.name = form.cleaned_data['name'] module.describe = form.cleaned_data['describe'] module.project = form.cleaned_data['project'] module.save() return HttpResponseRedirect('/manage/module_manage/') else: if mid: form = ModuleForm(instance=Module.objects.get(id=mid)) return render(request, 'module_manage.html', { 'form': form, "type": "edit", })
def edit_module(request, pid): ''' 编辑模块功能 ''' if request.method == "POST": form = ModuleForm(request.POST) if form.is_valid(): name = form.cleaned_data["name"] describe = form.cleaned_data["describe"] project = form.cleaned_data["project"] Model.objects.filter(id=pid).update(name=name, describe=describe, project=project) return HttpResponseRedirect('/manage/module_manage/') else: if pid: form = ModuleForm(instance=Model.objects.filter(id=pid).first()) #project_data = Project.objects.filter(id=pid).first() return render(request, "module_manage.html", { "type": "edit", "form": form, "id": pid })
def edit_module(request, mid): module = Module.objects.get(id=mid) if request.method == 'POST': #提交表单的post请求 # form = ModuleForm(request.POST) #用ProjectForm校验表单数据 # 如果是post,instance=article当前数据填充表单,并用data=request.POST获取到表单里的内容 form = ModuleForm(instance=module, data=request.POST) form.save() # 保存 if form.is_valid(): #判断表单数据校验结果 return HttpResponseRedirect('/manage/module_manage/') else: #进入表单页面的get请求 if mid: form = ModuleForm(instance=module) return render(request, 'module_manage.html', { 'form': form, 'type': 'edit' })