Exemplo n.º 1
0
def add_product(request):

    if request.method == "POST":

        product_form = ProductForm(request.POST, prefix="product")
        stock_form = StockForm(request.POST, prefix="stock")

        if product_form.is_valid() and stock_form.is_valid():

            product_save = product_form.save()

            stock_save = stock_form.save(commit=False)

            stock_save.stock_product_id = product_save

            stock_save.save()

            return redirect(order_index)

        else:
            print(form.errors)

    else:
        context = {"product_form": ProductForm(prefix="product"), "stock_form": StockForm(prefix="stock")}

    return render(request, "add_product.html", context)
Exemplo n.º 2
0
def add_product(request):

    context = {}

    if request.method == 'POST':

        product_form = ProductForm(request.POST, prefix='product')
        stock_form = StockForm(request.POST, prefix='stock')

        if product_form.is_valid() and stock_form.is_valid():

            product_save = product_form.save()

            stock_save = stock_form.save(commit=False)

            stock_save.stock_product_id = product_save

            stock_save.save()

            return redirect(order_index)

        else:
            print(form.errors)

    else:
        context.update({'product_form': ProductForm(prefix='product'), 'stock_form': StockForm(prefix='stock')})

    return render(request, 'add_product.html',context)