django 2表单不想保存在模型中

时间:2019-03-27 21:02:44

标签: python django django-views

该表单不想将输入保存在model中。 我处理了一个从模型中获取数据的视图,然后用表单输入对其进行验证,然后将所有数据发布到另一个新模型表中

def additemview(request, form2=profiledeviceForm()):
form1 = AdditemForm()
if request.method == 'POST':
    form1 = AdditemForm(request.POST)
    form2 = profiledeviceForm(request.POST)
    try:
        if form1.is_valid():
            text = form1.cleaned_data['serial']
            queryset = adddevice.objects.get(serial=text)
            text2=form1.cleaned_data['status']

            form2 = profiledeviceForm(
                initial={'serial': queryset.serial, 'user': request.user, 'label': queryset,'tag':text2})
            if request.method == 'POST':
               if form2.is_valid():
                   form2.save()
            context = {"queryset": queryset, "form2": form2, }
            return render(request, "adddevice.html", context)

    except ObjectDoesNotExist:
        return render(request, "notexist.html", {})
context = {"form1": form1,}
return render(request,"additem.html",context)

0 个答案:

没有答案