Beispiel #1
0
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})
Beispiel #2
0
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:'})
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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:'})
Beispiel #6
0
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)
Beispiel #7
0
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})
Beispiel #8
0
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)
Beispiel #9
0
 def get_context_data(self, **kwargs):
     context = super(OrderView, self).get_context_data()
     context['form'] = ProductForm()
     return context