def add_product(request): form = ProductForm(request.POST) if request.method == 'POST': form = ProductForm(request.POST or None, request.FILES) if form.is_valid(): form.save() return redirect('/gadmin') else: print(form.errors) else: form = ProductForm(request.POST, request.FILES) return render(request, 'Products.html', {'form': form})
def create_product(request): if request.method == 'POST': form = ProductForm(request.POST) if form.is_valid(): form.save() return redirect('products') else: form = ProductForm() return render(request, 'accounts/product_form.html', {'form':form, 'header': 'Create new product:'})
def createProduct(request): form = ProductForm() if request.method == 'POST': form = ProductForm(request.POST) if form.is_valid(): form.save() return redirect('/') context = {'form': form} return render(request, 'product/product_create.html', context)
def add_product(request): if request.method == "POST": form = ProductForm(request.POST) if form.is_valid(): form.save() return redirect('/product') else: form = ProductForm() context = {'form': form} return render(request, 'crmaccounts/add_product.html', context)
def update_product(request, pk): product = Product.objects.get(id = pk) form = ProductForm(instance = product) if request.method == 'POST': form = ProductForm(request.POST, instance = product) if form.is_valid(): form.save() return redirect('products') #redirect to products.html return render(request, 'accounts/product_form.html', {'form':form, 'header':'Update product:'})
def updateProduct(request, pk): product = Product.objects.get(id=pk) form = ProductForm(instance=product) if request.method == 'POST': form = ProductForm(request.POST, instance=product) if form.is_valid(): form.save() return redirect('/products/') context = {'form': form} return render(request, 'product/product_update.html', context)
def update_Product(request,prod_id): record = Product.objects.get(prod_id=prod_id) if request.method == 'POST': record = Product.objects.get(prod_id=prod_id) form = ProductForm(request.POST or None,request.FILES,instance=record) if form.is_valid(): form.save() print('Your profile was successfully updated!') return redirect('/ShowProduct') else: print(form.errors) else: form = ProductForm(instance=record) return render(request, 'edit_Product.html', {'form': form,'key':record})
def update_product(request, pk): product = Products.objects.get(id=pk) if request.method == "POST": form = ProductForm( request.POST, instance=product, ) if form.is_valid(): form.save() return redirect('/product') else: form = ProductForm(instance=product) context = {'form': form} return render(request, 'crmaccounts/update_product.html', context)
def get_context_data(self, **kwargs): context = super(OrderView, self).get_context_data() context['form'] = ProductForm() return context