Example #1
0
    def post(self, request):
        success_url = reverse_lazy('products:list')
        form = ProductModelForm(request.POST)

        if form.is_valid():
            form.save()
            return redirect(success_url)

        return render(request, 'products/create.html', {'form': form})
Example #2
0
def create_product(request):
    form = ProductModelForm(request.POST or None)

    if form.is_valid():
        form.save()
        return redirect("products:list")

    context = {"form": form}
    return render(request, "products/create.html", context=context)
Example #3
0
def update_product(request, product_id):
    product = Product.objects.get(pk=product_id)
    form = ProductModelForm(data=request.POST or None, instance=product)

    if form.is_valid():
        form.save()
        return redirect("products:list")

    context = {"form": form}

    return render(request, "products/update.html", context=context)
Example #4
0
def product_create(request):
    title = 'Добавить товар'
    template_name = 'products/create.html'
    success_url = reverse_lazy('products:catalog')
    form = ProductModelForm(request.POST)

    if request.method == 'POST':
        if form.is_valid():
            form.save()

            return redirect(success_url)

    context = {'form': form, 'title': title, 'menu': get_menu()}

    return render(request, template_name, context)
Example #5
0
def product_model_create(request):
    template_write_name = 'Create product'
    template_name = 'products/create.html',
    success_url = reverse_lazy('products:product_list')
    form = ProductModelForm(request.POST)

    if request.method == 'POST':
        if form.is_valid():
            form.save()

            return redirect(success_url)

    return render(request, template_name, {
        'form': form,
        'template_write_name': template_write_name
    })
Example #6
0
def update_view(request, object_id=None):
    product = get_object_or_404(Product, id=object_id)
    form = ProductModelForm(request.POST or None, instance=product)
    if not form.is_valid():
        print('---FORM-NOT-VALID---')
        print(form.errors)
    else:
        if form.is_valid():
            instance=form.save(commit=False)
            instance.save()
        template = "form.html"
        context = {
            "object":product,
            "form":form,
            "submit_btn":"Update Product",
            }
        return render(request, template, context)
Example #7
0
def create_product(request):
    if request.method == 'POST':
        #salvar form, trazendo formulário para criação de produto
        form = ProductModelForm(request.POST)
        if form.is_valid():
            #True -> é valido
            form.save()
            form = ProductModelForm()
    else:
        # Get form
        form = ProductModelForm()

    context = {'form': form}
    return render(request, 'products/create.html', context=context)
Example #8
0
def product_delete(request, pk):
    title = 'Удалить товар'
    template_name = 'products/delete.html'
    success_url = reverse_lazy('products:catalog')
    obj = get_object_or_404(Product, pk=pk)

    form = ProductModelForm(instance=obj)

    if request.method == 'POST':
        form = ProductModelForm(request.POST, instance=obj)
        if form.is_valid():
            obj.delete()

            return redirect(success_url)

    context = {'form': form, 'title': title, 'menu': get_menu()}

    return render(request, template_name, context)
Example #9
0
def product_create_view(request):
    form = ProductModelForm()
    success_url = reverse('products:list')
    if request.method == 'POST':
        form = ProductModelForm(data=request.POST)
        if form.is_valid():
            form.save()
            return redirect(success_url)
    return render(request, 'products/create.html', {'form': form})
Example #10
0
def create_produtct(request):
    if request.method == 'POST':
        form = ProductModelForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('products:list')
    else:
        form = ProductModelForm()

    context = {'form': form}
    return render(request, 'products/create.html', context=context)
Example #11
0
def product_create_view(request, *args, **kwargs):
    form = ProductModelForm(request.POST or None)
    if form.is_valid():
        obj = form.save(commit=False)
        obj.user = request.user
        obj.save()
        form = ProductModelForm()
    return render(request, "forms.html", {"form": form})
Example #12
0
def product_update_view(request, pk):
    obj = get_object_or_404(Product, pk=pk)
    form = ProductModelForm(instance=obj)
    success_url = reverse('products:list')
    if request.method == 'POST':
        form = ProductModelForm(request.POST,
                                files=request.FILES,
                                instance=obj)
        if form.is_valid():
            form.save()
            return redirect(success_url)
    return render(request, 'products/update.html', {'form': form})
Example #13
0
def update_product(request, product_id):
    product = Product.objects.get(pk=product_id)

    if request.method == 'POST':
        form = ProductModelForm(data=request.POST, instance=product)
        if form.is_valid():
            form.save()
            return redirect('products:list')
    else:
        form = ProductModelForm(instance=product)

        context = {'form': form}

        return render(request, 'products/update.html', context=context)
Example #14
0
def create_product(request):
    if request.method == 'POST':
        #salvar formulario
        form = ProductModelForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/products/list')
    else:
        #get formulario
        form = ProductModelForm(request.GET)

    context = {'form': form}

    return render(request, 'products/Create.html', context=context)
def create_product(request):
    if request.method == 'POST':
        #Salvar form
        form = ProductModelForm(request.POST)
        if form.is_valid():
            #True -> é valido
            form.save()
            return redirect('products:list')  #Retorna para a lista de produtos
    else:  #Não valido
        #Get form
        form = ProductModelForm()

    context = {  #Sempre é um dicionário
        'form': form
    }
    return render(request, 'products/create.html', context=context)
Example #16
0
def create_product(request):
    if request.method == 'POST':
        # Salvar form
        form = ProductModelForm(request.POST)
        if form.is_valid():
            # True -> é válido
            form.save()
            return redirect(
                'products:list')  # retorna para a página de lista de produtos
    else:
        # Get Form
        form = ProductModelForm()

    # form = ProductModelForm()
    context = {'form': form}

    return render(request, 'products/create.html', context=context)
def update_product(request, product_id):
    product = Product.objects.get(pk=product_id)

    if request.method == 'POST':
        form = ProductModelForm(data=request.POST, instance=product)
        if form.is_valid():
            #True -> é valido
            form.save()
            return redirect('products:list')
    else:  #Não valido
        #Get form
        form = ProductModelForm(instance=product)  #id = instancia

    context = {  #Sempre é um dicionário
        'form': form
    }
    return render(request, 'products/update.html', context=context)
Example #18
0
def product_model_update(request, pk):
    template_write_name = 'Update product'
    template_name = 'products/create.html',
    success_url = reverse_lazy('products:product_list')
    obj = get_object_or_404(Product, pk=pk)
    form = ProductModelForm(instanse=obj)

    if request.method == 'POST':
        form = ProductModelForm(request.POST, instanse=obj)
        if form.is_valid():
            form.save()

            return redirect(success_url)

    return render(request, template_name, {
        'form': form,
        'template_write_name': template_write_name
    })
Example #19
0
def create_view(request):
    form = ProductModelForm(request.POST or None, request.FILES or None)


    if not form.is_valid():
        print('---FORM-NOT-VALID---')
        print(form.errors)
    else:
        if form.is_valid():
            instance = form.save(commit=False)
            instance.sale_price=instance.price
            instance.save()
            form.save()
        template="form.html"
        context={
            "form":form,
            "submit_btn":"Create Product",
            }
        return render(request, template, context)
Example #20
0
def product_update(request, pk):

    success_url = reverse_lazy('products:list')

    obj = get_object_or_404(Product, id=pk)

    form = ProductModelForm(instance=obj)

    if request.method == 'POST':

        form = ProductModelForm(request.POST, instance=obj)

        if form.is_valid():

            form.save()

            return redirect(success_url)

    return render(request, 'products/create.html', {'form': form})
Example #21
0
def update_product(request, product_id):
    product = Product.objects.get(pk=product_id)

    if request.method == 'POST':
        #salvar form, trazendo dados instaciados em product para o formulário da  tela.
        form = ProductModelForm(data=request.POST, instance=product)
        if form.is_valid():
            form.save()
            return redirect('products:list')
    else:
        # GET
        # Trazendo dados instanciados em product para o formulário.
        form = ProductModelForm(instance=product)

    context = {
        'form': form,
    }

    return render(request, 'products/update.html', context=context)
Example #22
0
 def get(self, request):
     form = ProductModelForm(
     )
     return render(request, 'products/create.html', {'form': form})