Django inlineformset创建重复的查询

时间:2016-07-26 12:37:14

标签: django forms

我有一个表单,您可以在其中将产品添加到仓库。仓库是外键。我的视图重复了导致服务器超时的数据库查询。

def warehouse_in(request):
    catalog_doc = CatalogDocument.objects.all()
    contractor = Contractor.objects.all()
    currency = Currency.objects.all()
    if request.POST:
    form = WarehouseInForm(request.POST)
    if form.is_valid():
        warehousein = form.save(commit=False)
        warehousein_formset = WarehouseInFormSet(request.POST, instance=warehousein)
        if warehousein_formset.is_valid():
            warehousein.save()
            warehousein_formset.save()
            return redirect('catalog.views.warehouse_in_list')
else:
    form = WarehouseInForm()
    warehousein_formset = WarehouseInFormSet(instance=WarehouseIn())
return render(request, "catalog/templates/warehouse_in_form.html", {
    'form': form,
    'catalog_doc': catalog_doc,
    'contractor': contractor,
    'currency': currency,
    'warehousein_formset': warehousein_formset,
}, context_instance=RequestContext(request))

来自ddtb的信息:

SELECT•••FROM" catalog_product"在哪里" catalog_product"。" id" = 1 重复3次。

0 个答案:

没有答案