def product_create_view(request, *args, **kwargs):
    if request.method == "GET":
        return render(request,
                      'product_create.html',
                      context={'form': ProductForm()})
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            description = form.cleaned_data['description']
            category = form.cleaned_data['category']
            amount = form.cleaned_data['amount']
            price = form.cleaned_data['price']
            product = Product.objects.create(name=name,
                                             description=description,
                                             category=category,
                                             amount=amount,
                                             price=price)
            return redirect('product_view', pk=product.pk)
        else:
            return render(request,
                          'product_create.html',
                          context={'form': form})
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
Ejemplo n.º 2
0
def add_new_product(request, *args, **kwargs):

    if request.method == 'GET':

        form = ProductForm()

        return render(request, 'create.html', context={'form': form})

    elif request.method == 'POST':

        form = ProductForm(data=request.POST)

        if form.is_valid():

            Product.objects.create(
                name=form.cleaned_data['name'],
                description=form.cleaned_data['description'],
                category=form.cleaned_data['category'],
                amount=form.cleaned_data['amount'],
                price=form.cleaned_data['price'])

            return redirect('index')

        else:

            return render(request, 'create.html', context={'form': form})
Ejemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     form = ProductForm(request.POST, request.FILES)
     if form.is_valid():
         form.save()
         return self.form_valid(form)
     else:
         return self.form_invalid(form)
Ejemplo n.º 4
0
def product_update_view(request, pk):
    product = get_object_or_404(Product, pk=pk)
    if request.method == 'GET':
        form = ProductForm(
            data={
                "name": product.name,
                "description": product.description,
                "category": product.category,
                "remainder": product.remainder,
                "price": product.price
            })
        return render(request,
                      "update.html",
                      context={
                          "form": form,
                          "product": product
                      })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product.name = form.cleaned_data["name"]
            product.description = form.cleaned_data["description"]
            product.category = form.cleaned_data["category"]
            product.remainder = form.cleaned_data['remainder']
            product.price = form.cleaned_data['price']
            product.save()
            return redirect("product_detail", pk=product.pk)
        else:
            return render(request,
                          "update.html",
                          context={
                              "form": form,
                              "product": product
                          })
Ejemplo n.º 5
0
def product_update_view(request, pk):
    product = get_object_or_404(Product, pk=pk)
    if request.method == 'GET':
        form = ProductForm(
            data={
                'name': product.name,
                'description': product.description,
                'category': product.category,
                'amount': product.amount,
                'price': product.price
            })
        return render(request,
                      'update.html',
                      context={
                          'form': form,
                          'product': product
                      })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product.name = form.cleaned_data['name']
            product.description = form.cleaned_data['description']
            product.category = form.cleaned_data['category']
            product.amount = form.cleaned_data['amount']
            product.price = form.cleaned_data['price']
            product.save()
            return redirect('product_detail', pk=product.pk)
        else:
            return render(request,
                          'update.html',
                          context={
                              'form': form,
                              'product': product
                          })
def product_update_view(request, pk):
    product = get_object_or_404(Product, pk=pk)
    form = ProductForm(data=request.POST)

    if request.method == 'GET':
        form = ProductForm(
            data={
                'name_of_product': product.name_of_product,
                'description': product.description,
                'status': product.status,
                'date': product.date,
                'count': product.count
            })
        return render(request,
                      'update.html',
                      context={
                          'product': product,
                          'form': form
                      })

    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product.name_of_product = form.cleaned_data['name_of_product']
            product.date = form.cleaned_data['date']
            product.status = form.cleaned_data['status']
            product.description = form.cleaned_data['description']
            product.count = form.cleaned_data['count']
            product.save()
            return redirect('product_view', pk=product.pk)
Ejemplo n.º 7
0
def product_create_view(request):
    if request.method == "GET":
        form = ProductForm()
        return render(request,
                      'create.html',
                      context={
                          'category_choices': CATEGORY_CHOICES,
                          'form': form
                      })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product = Product.objects.create(
                name=form.cleaned_data['name'],
                description=form.cleaned_data['description'],
                category=form.cleaned_data['category'],
                amount=form.cleaned_data['amount'],
                price=form.cleaned_data['price'])
            return redirect('product_view', pk=product.pk)

        else:
            return render(request,
                          'create.html',
                          context={
                              'category_choices': CATEGORY_CHOICES,
                              'form': form
                          })
Ejemplo n.º 8
0
def add_product(request):
    if request.method == 'GET':
        form = ProductForm()
        return render(request,
                      'add_product.html',
                      context={
                          'form': form,
                          'category': category
                      })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            product = Product.objects.create(name=data['name'],
                                             description=data['description'],
                                             category=data['category'],
                                             count=data['count'],
                                             price=data['price'])
            return redirect('product_view', pk=product.pk)
        else:
            return render(request,
                          'add_product.html',
                          context={
                              'form': form,
                              'category': category
                          })
Ejemplo n.º 9
0
def product_create_view(request):
    if request.method == 'GET':
        form = ProductForm()
        return render(request, 'create.html', context={'form': form})
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if not form.is_valid():
            return render(request, 'create.html', context={'form': form})
        Product.objects.create(name=form.cleaned_data['name'],
                               description=form.cleaned_data['description'],
                               category=form.cleaned_data['category'],
                               remain=form.cleaned_data['remain'],
                               price=form.cleaned_data['price'])
        return redirect('index')
Ejemplo n.º 10
0
def product_create_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = ProductForm()
        return render(request, 'create.html', context={"form": form})
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product = Product.objects.create(
                name=form.cleaned_data["name"],
                desctiption=form.cleaned_data["description"],
                category=form.cleaned_data["category"],
                remainder=form.cleaned_data["remainder"],
                price=form.cleaned_data['price'])
            return redirect("product_detail_view", pk=product.pk)
        else:
            return render(request, "create.html", context={"form": form})
Ejemplo n.º 11
0
def product_add_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = ProductForm()
        return render(request, 'add.html', context={'form': form})
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product = Product.objects.create(
                name=form.cleaned_data['name'],
                description=form.cleaned_data['description'],
                category=form.cleaned_data['category'],
                balance=form.cleaned_data['balance'],
                cost=form.cleaned_data['cost'],
            )
            return redirect('product_view', pk=product.pk)
        else:
            return render(request, 'add.html', context={'form': form})
Ejemplo n.º 12
0
def product_create_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = ProductForm()
        return render(request, 'product_create.html', context={'form': form})
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            task = Product.objects.create(name=data['name'],
                                          description=data['description'],
                                          category=data['category'],
                                          amount=data['amount'],
                                          price=data['price'])
            return redirect('product_view', pk=task.pk)
        else:
            return render(request,
                          'product_create.html',
                          context={'form': form})
Ejemplo n.º 13
0
def product_update_view(request, pk):
    product = get_object_or_404(Product, pk=pk)
    if request.method == "GET":
        form = ProductForm(
            initial={
                'name': product.name,
                'description': product.description,
                'category': product.category,
                'amount': product.amount,
                'price': product.price
                # форматирование перед выводом для DateTime.
                #'publish_at': make_naive(product.publish_at)\
                #.strftime(BROWSER_DATETIME_FORMAT)
                # для дат выглядит просто как:
                # 'publish_at': article.publish_at
            })
        return render(request,
                      'product_update.html',
                      context={
                          'form': form,
                          'product': product
                      })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            # Article.objects.filter(pk=pk).update(**form.cleaned_data)
            product.name = form.cleaned_data['name']
            product.description = form.cleaned_data['description']
            product.category = form.cleaned_data['category']
            product.amount = form.cleaned_data['amount']
            product.price = form.cleaned_data['price']
            product.save()
            return redirect('product_view', pk=product.pk)
        else:
            return render(request,
                          'product_update.html',
                          context={
                              'product': product,
                              'form': form
                          })
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
Ejemplo n.º 14
0
def add_product(request, *args, **kwargs):
    if request.method == 'GET':
        form = ProductForm()
        return render(request,
                      'add_product.html',
                      context={
                          'form': form,
                          'product_status_choices': product_status_choices
                      })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product = Products.objects.create(
                name=form.cleaned_data['name'],
                description=form.cleaned_data['description'],
                status=form.cleaned_data['status'],
                balance=form.cleaned_data['balance'],
                price=form.cleaned_data['price'])
            return redirect('product_view', pk=product.pk)
        else:
            return render(request, 'add_product.html', context={'form': form})
def product_create_view(request, *args, **kwargs):
    if request.method == 'GET':

        form = ProductForm()

        return render(request, 'create.html', context={'form': form})

    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product = Product.objects.create(
                name_of_product=form.cleaned_data['name_of_product'],
                date=form.cleaned_data['date'],
                description=form.cleaned_data['description'],
                count=form.cleaned_data['count'],
                status=form.cleaned_data['status'])

            return redirect('product_view', pk=product.pk)

        else:

            return render(request, 'create.html', context={'form': form})
def form_storage_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = ProductForm()
        return render(request, 'form.html', context={
            'form': form,
            'status_choices': PRODUCT_OTHER_CHOICE
        })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)

        if not form.is_valid():
            return render(request, 'form.html', context={'form': form, 'status_choices': PRODUCT_OTHER_CHOICE})

        Product.objects.create(
            name=form.cleaned_data['name'],
            description=form.cleaned_data['description'],
            category=form.cleaned_data['category'],
            amount=form.cleaned_data['amount'],
            price=form.cleaned_data['price']

        )
        return redirect('index')
def detailed_update_view(request, pk):
    task = get_object_or_404(Product, pk=pk)
    if request.method == 'GET':
        form = ProductForm(data={
            'name': task.name,
            'description': task.description,
            'category': task.category,
            'amunt': task.amount,
            'price': task.price
        })
        return render(request, 'update.html', context={'form': form, 'task': task})
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            task.name = form.cleaned_data['name']
            task.description = form.cleaned_data['description']
            task.category = form.cleaned_data['category']
            task.amount = form.cleaned_data['amount']
            task.price = form.cleaned_data['price']
            task.save()
            return redirect('detailed', pk=task.pk)

        return render(request, 'update.html', context={'form': form, 'task': task})
Ejemplo n.º 18
0
def product_edit_view(request, pk):
    product = get_object_or_404(Product, pk=pk)
    if request.method == 'GET':
        form = ProductForm(data={
            'name': product.name,
            'description': product.description,
            'category': product.category,
            'balance': product.balance,
            'cost': product.cost,
        })
        return render(request, 'edit.html', context={'form': form, 'product': product})
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product.name = form.cleaned_data['name']
            product.description = form.cleaned_data['description']
            product.category = form.cleaned_data['category']
            product.balance = form.cleaned_data['balance']
            product.cost = form.cleaned_data['cost']
            product.save()
            return redirect('product_view', pk=product.pk)
        else:
            return render(request, 'edit.html', context={'form': form, 'product': product})
Ejemplo n.º 19
0
def update_product(request, pk):
    try:
        products = get_object_or_404(Products, pk=pk)
        if request.method == 'GET':
            form = ProductForm(
                data={
                    'name': products.name,
                    'description': products.description,
                    'status': products.status,
                    'balance': products.balance,
                    'price': products.price
                })
            return render(request,
                          'edit.html',
                          context={
                              'products': products,
                              'form': form
                          })
        elif request.method == "POST":
            form = ProductForm(data=request.POST)
            if form.is_valid():
                products.name = form.cleaned_data['name']
                products.description = form.cleaned_data['description']
                products.status = form.cleaned_data['status']
                products.balance = form.cleaned_data['balance']
                products.price = form.cleaned_data['price']
                products.save()
                return redirect('product_view', pk=products.pk)
            else:
                return render(request,
                              'edit.html',
                              context={
                                  'form': form,
                                  'products': products
                              })
    except Products.DoesNotExist:
        return HttpResponseNotFound("<h2>Article not found</h2>")
Ejemplo n.º 20
0
def product_update_view(request, pk):
    product = get_object_or_404(Product, pk=pk)
    if request.method == "GET":
        form = ProductForm(
            initial={
                'name': product.name,
                'description': product.description,
                'category': product.category,
                'amount': product.amount,
                'price': product.price
            })
        return render(request,
                      'product_update.html',
                      context={
                          'form': form,
                          'Products': product
                      })
    elif request.method == 'POST':
        form = ProductForm(data=request.POST)
        if form.is_valid():
            product.name = form.cleaned_data['name']
            product.description = form.cleaned_data['description']
            product.category = form.cleaned_data['category']
            product.amount = form.cleaned_data['amount']
            product.price = form.cleaned_data['price']
            product.save()
            return redirect('product_view')
        else:
            return render(request,
                          'product_update.html',
                          context={
                              'Products': product,
                              'form': form
                          })
    else:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])