def new_product(request): if request.method == "POST": nowy = Product(timestamp=timezone.now()) form1 = ProductForm(instance=nowy, data=request.POST) if form1.is_valid(): form1.save() return redirect("index") return redirect("shop_admin")
def productadd(request): if request.method == 'POST': form = ProductForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('/products') else: form = ProductForm() return render(request, 'shop/productadd.html', {'form': form})
def update_product(request,pid): if request.method=='GET': p = Product.objects.get(pk=pid) forms = ProductForm(instance=p) return render(request,'product_update.html',{'forms':forms}) else: p = Product.objects.get(pk=pid) forms = ProductForm(instance=p,data=request.POST) if forms.is_valid(): forms.save() return HttpResponseRedirect('/')
def show_product(request): if request.method == 'POST': forms = ProductForm(request.POST,request.FILES) print request.POST if forms.is_valid(): forms.save() return HttpResponseRedirect('/') else: forms = ProductForm() context_dict = {'forms':forms} return render (request,'product.html',context_dict)
def product_create_view(request): if request.method == "POST": form = ProductForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('shop:product_list') else: form = ProductForm() return render(request, 'shop/product/add_product.html', {'form':form})
def product_form_view(request): form = ProductForm() if request.method == 'POST': form = ProductForm(request.POST) if form.is_valid(): form.save() return redirect(reverse_lazy('products')) else: pass return render(request, 'product_form.html', context={ 'form': form })
def add_products(request, template_name='shop/add_products.html'): if request.method == 'POST': form = ProductForm(request.POST) if form.is_valid(): form.save(request.user) return HttpResponseRedirect(reverse('show_products')) else: form = ProductForm() context = RequestContext(request) return render_to_response(template_name, {'form': form}, context_instance=context)
def product_form(request): if request.method =='POST': form = ProductForm(request.POST) if form.is_valid(): form.save() return redirect( 'Profile:product_form' ) else: form = ProductForm() #form = {'form': form} #args = {'form': form} return render(request, 'Profile/product_form.html',{'form': form} )
def product_new(request): if request.method == "POST": form = ProductForm(request.POST) if form.is_valid(): product = form.save(commit=False) product.created_date = timezone.now() product.save() return redirect('shop:product_detail', id=product.id) else: form = ProductForm() return render(request, 'shop/product_edit.html', {'form': form})
def add_product(request): if request.method == 'POST': product_form = ProductForm( request.POST, request.FILES, ) if product_form.is_valid(): # save product to database product_form.save() messages.success(request, 'The product has been added.') # redirect to the dashboard return redirect(reverse('dashboard')) product_form = ProductForm() context = { 'product_form': product_form, } return render(request, 'add_product.html', context)
def product_edit(request, id): product = get_object_or_404(Product, id=id) if request.method == "POST": form = ProductForm(request.POST, instance=product) if form.is_valid(): product = form.save(commit=False) product.created_date = timezone.now() product.save() return redirect('shop:product_detail', id=product.id) else: form = ProductForm(instance=product) return render(request, 'shop/product_edit.html', {'form': form})
def product_new(request): if request.method == "POST": form = ProductForm(request.POST) if form.is_valid(): product = form.save(commit=False) product.created = timezone.now() product.save() products = Product.objects.filter(available=True) return render(request, 'portfolio/admin.html', {'products': products}) else: form = ProductForm() return render(request, 'portfolio/product_add.html', {'form': form})
def update_product(request,pk): product = get_object_or_404(Product,pk = pk) form = ProductForm(request.POST or None,request.FILES or None,instance = product) if form.is_valid(): product = form.save(commit=False) image = form.cleaned_data['image'] product.image = image product.save() return redirect('shop:homepage') return render(request,'shop/product_update.html',{ 'form':form })
def employee_product_edit(request, pk): product = get_object_or_404(Product, pk=pk) print("I am here") if request.method == "POST": # update form = ProductForm(request.POST, instance=product) if form.is_valid(): product = form.save(commit=False) product.updated = timezone.now() product.save() products = Product.objects.filter(available=True) return render(request, 'portfolio/admin.html', {'products': products}) else: # edit print("I am here") form = ProductForm(instance=product) return render(request, 'portfolio/product_update.html', {'form': form})
def new_product(request, subcategory_pk): subcategory = get_object_or_404(SubCategory, pk=subcategory_pk) categories = Category.objects.order_by('-name') if request.method == 'POST': form = ProductForm(request.POST, request.FILES) if form.is_valid(): product = form.save(commit=False) product.sub_category = subcategory product.save() return redirect('frontdesk:categories') else: form = ProductForm() return render(request, 'frontdesk/categories.html', { 'form': form, 'subcategory': subcategory, 'categories': categories })
def create_product(request): if request.method == 'POST': form = ProductForm(request.POST,request.FILES) if form.is_valid(): product = form.save(commit=False) print(product) image = form.cleaned_data['image'] product.image = image product.save() return redirect('shop:homepage') else: return render(request,'shop/create_product.html',{ 'form':ProductForm() }) form = ProductForm() return render(request,'shop/create_product.html',{'form':form})
def create_item_View(request): """ Provide the ability to create item post """ form = ProductForm(request.POST or None) user = get_object_or_404(User, id=request.user.id) categories = Category.objects.all() if request.method == 'POST': if form.is_valid(): instance = form.save(commit=False) instance.user = user instance.save() # for save tags form.save_m2m() return redirect( reverse("ecomapp:single-item", kwargs={'id': instance.id})) context = {'form': form, 'categories': categories} return render(request, 'ecomapp/post-item.html', context)