mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
form create product | add product in comanda
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -14,7 +14,6 @@ Produtos
|
||||
|
||||
|
||||
|
||||
|
||||
{% block 'body' %}
|
||||
|
||||
|
||||
@@ -37,14 +36,22 @@ Produtos
|
||||
|
||||
|
||||
|
||||
<div class="modal" id="myModal">
|
||||
<div class="modal" id="Modal-create-product">
|
||||
<div class="modal-content">
|
||||
<form id="productForm" method="post" action="{% url 'create_product' %}">
|
||||
<form action="{% url 'create_product' %}" id="productForm" method="post" >
|
||||
{% csrf_token %}
|
||||
<h2>Cadastro de Produto</h2>
|
||||
<input type="text" id="productName" name="name" required placeholder="Nome"><br>
|
||||
<input type="number" step="0.01" id="productPrice" name="price" required placeholder="Preço"><br>
|
||||
<input type="number" step="1" id="productqtd" name="qtd" required placeholder="Quantidade"><br>
|
||||
<textarea id="productDescription" name="description" rows="4" required placeholder="Descrição"></textarea><br>
|
||||
<input type="number" step="1" id="productqtd" name="qtd" placeholder="Quantidade"><br>
|
||||
<select name="select-categorie" >
|
||||
|
||||
{% for categorie in categories %}
|
||||
<option value="{{categorie.id}}">{{categorie.name}}</option>
|
||||
{% endfor %}
|
||||
|
||||
</select>
|
||||
<textarea id="productDescription" name="description" rows="4" placeholder="Descrição"></textarea><br>
|
||||
<button type="submit">Salvar</button>
|
||||
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
||||
</form>
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
|
||||
from django.urls import path, include
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.products, name='products'),
|
||||
path('create_product', views.createProduct, name='create_product'),
|
||||
|
||||
|
||||
|
||||
]
|
||||
|
||||
@@ -11,11 +11,10 @@ def products(request):
|
||||
|
||||
|
||||
def createProduct(request):
|
||||
print(request.POST)
|
||||
name = request.POST.get('name')
|
||||
description = request.POST.get('description')
|
||||
price = request.POST.get('price')
|
||||
category = request.POST.get('category')
|
||||
category = Categories.objects.get(id = int(request.POST.get('select-categorie')))
|
||||
product = Product(name=name, description=description, price=price, category=category)
|
||||
product.save()
|
||||
return redirect('/products')
|
||||
|
||||
Reference in New Issue
Block a user