我有一个inLineForm,现在我要向ProductDetails添加一个新表单。添加表单后,ge错误“ 模块”丢失了。我不确定是什么问题。
我要这样做的是:我正在创建一个名为product的对象,该对象通过inLineForm将信息放入这些表中:Product,Product Details和Product size
这是方法:
def restaurant_add_product(request):
fields = ['size', 'price']
ProductSizeFormSet = inlineformset_factory(Product, ProductDetails, ProductSize, fields=fields)
form = ProductForm(request.POST or None, request.FILES or None)
product_details_forms = ProductDetailForm(request.POST or None, instance = Product.objects.get(id = product_id))
formset = ProductSizeFormSet(request.POST or None)
products to each restaurant
if request.method == "POST":
if form.is_valid():
product = form.save(commit=False)
product.restaurant = request.user.restaurant
product.save()
if product_details_forms.is_valid():
productDetails = product_details_forms.save(commit=False)
productDetails.save()
if formset.is_valid():
formset.save()
else:
print(formset.errors)
return redirect(restaurant_product)
return render(request, 'restaurant/add-product.html', {
"form": form,
"product_details_forms": product_details_forms,
'formset': formset
})