mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: edit product
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -20,7 +20,7 @@ Produtos
|
||||
<body>
|
||||
<div class="grid-container">
|
||||
<div ><input type="text"></div>
|
||||
<button id="openModal">Adicionar Novo Produto</button>
|
||||
<button onclick="openModal()" id="openModal">Adicionar Novo Produto</button>
|
||||
|
||||
<table id="list-products">
|
||||
<tr>
|
||||
@@ -34,13 +34,13 @@ Produtos
|
||||
{% for product in products %}
|
||||
|
||||
<tr>
|
||||
<td>{{product.name}}</td>
|
||||
<td>R$ {{product.price}}</td>
|
||||
<td>{{product.quantity}}</td>
|
||||
<td>{{product.category.name}}</td>
|
||||
<td id="name-{{product.id}}" >{{product.name}}</td>
|
||||
<td id="price-{{product.id}}" >R$ {{product.price}}</td>
|
||||
<td id="quantity-{{product.id}}" >{{product.quantity}}</td>
|
||||
<td id="category-{{product.id}}" >{{product.category.name}}</td>
|
||||
<td>
|
||||
<div class="grid-buttons">
|
||||
<button>📝 Editar</button>
|
||||
<button onclick="editProduct({{product.id}})" >📝 Editar</button>
|
||||
|
||||
<form action="{% url 'onOffproduct' %}" method="post">
|
||||
{% csrf_token %}
|
||||
@@ -72,15 +72,16 @@ Produtos
|
||||
|
||||
|
||||
<dialog id='Modal-create-product' >
|
||||
<article>
|
||||
<article >
|
||||
|
||||
<form action="{% url 'create_product' %}" id="productForm" method="post" >
|
||||
{% csrf_token %}
|
||||
<h2>Cadastro de Produto</h2>
|
||||
<input type="text" id="productId" name="productId" required hidden ><br>
|
||||
<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" placeholder="Quantidade"><br>
|
||||
<select name="select-categorie" >
|
||||
<select id="select-categorie" name="select-categorie" >
|
||||
|
||||
{% for categorie in categories %}
|
||||
<option value="{{categorie.id}}">{{categorie.name}}</option>
|
||||
@@ -88,9 +89,11 @@ Produtos
|
||||
|
||||
</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>
|
||||
<footer class="grid-buttons">
|
||||
<button type="submit">Salvar</button>
|
||||
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
</article>
|
||||
</dialog>
|
||||
|
||||
@@ -6,5 +6,6 @@ urlpatterns = [
|
||||
path('', views.products, name='products'),
|
||||
path('create_product', views.createProduct, name='create_product'),
|
||||
path('onOffproduct', views.onOffProduct, name='onOffproduct'),
|
||||
path('editProduct/<int:productId>/', views.editProduct, name='editProduct'),
|
||||
|
||||
]
|
||||
|
||||
@@ -27,4 +27,16 @@ def onOffProduct(request):
|
||||
product = Product.objects.get(id=product_id)
|
||||
product.active = not product.active
|
||||
product.save()
|
||||
return redirect('products')
|
||||
|
||||
def editProduct(request, productId):
|
||||
# id = request.POST.get('productId')
|
||||
product_id = productId
|
||||
product = Product.objects.get(id=product_id)
|
||||
product.name = request.POST.get('name')
|
||||
product.description = request.POST.get('description')
|
||||
product.price = request.POST.get('price')
|
||||
product.quantity = request.POST.get('qtd')
|
||||
product.category = Categories.objects.get(id = int(request.POST.get('select-categorie')))
|
||||
product.save()
|
||||
return redirect('products')
|
||||
Reference in New Issue
Block a user