保存模态窗体后,对象为无

时间:2015-12-16 10:53:33

标签: django django-forms

我正在为我的产品型号使用django表单,但实例返回为无

if request.user.is_authenticated:
        if request.method =='POST':
            form = ProductModelForm(request.POST)
            if form.is_valid():
                instance = form.save()
                product = instance.save()
                print product
                return HttpResponseRedirect(reverse("DataEntry"))
            else:
                return HttpResponseRedirect(reverse("DataEntry"))

        else:
            form = ProductModelForm()

            context = {
            'form' : form , 
            'products' : Product.objects.all().order_by('-timestamp')
            }
            return render(request, "products/dataentry.html", context)

这可能是什么问题? 需要帮助

1 个答案:

答案 0 :(得分:1)

调用for (var task of tasks) { for (var currentAssig of assigs) { var resourceId = currentAssig.resourceId; var relevantResource = RESOURCES.filter(function (res) { return res.ID === resourceId; }); // do whatever you want with your resource. } } 会返回实例。在您的情况下,您没有使用form.save(),因此无需保存实例。

form.save(commit=False)不同,form.save()会返回instance.save(),因此您当前正在为产品分配None

您可以将代码简化为:

None