mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
add product in comanda
This commit is contained in:
BIN
gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc
Normal file
BIN
gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
15
gestaoRaul/comandas/htmx_views.py
Normal file
15
gestaoRaul/comandas/htmx_views.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
from products.models import Product
|
||||
|
||||
|
||||
def listProduct(request):
|
||||
product = request.GET.get("search-product")
|
||||
products = Product.objects.filter(name__icontains=product)
|
||||
return render(request, "htmx_components/htmx_list_products.html", {"products": products})
|
||||
|
||||
def addProduct(request, product_id, comanda_id):
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
return render(request, "htmx_components/htmx_add_product.html",)
|
||||
@@ -58,8 +58,15 @@ Detalhes {{comanda.name}}
|
||||
<div class="modal-content">
|
||||
<form id="productForm" >
|
||||
<h2>Adicionar Produto <button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button></h2>
|
||||
<input type="text" id="search-product" name="search-product" required placeholder="Buscar Produto"><br>
|
||||
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'listProduct' %}" hx-trigger="keyup" hx-target="#product-list"><br>
|
||||
<div id="product-list" class="grid-list-products">
|
||||
{% for product in products %}
|
||||
|
||||
<div class="card" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#product-list">
|
||||
{{product.name}}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- <input type="number" step="1" id="product-qtd" name="qtd" required placeholder="Quantidade"><br> -->
|
||||
<!-- <button type="submit">Salvar</button> -->
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from comandas import htmx_views
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
@@ -10,3 +12,13 @@ urlpatterns = [
|
||||
|
||||
|
||||
]
|
||||
|
||||
|
||||
htmx_urlpatterns = [
|
||||
path('listProduct/', htmx_views.listProduct, name='listProduct'),
|
||||
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
|
||||
# path('removeProduct/', views.removeProduct, name='removeProduct'),
|
||||
|
||||
]
|
||||
|
||||
urlpatterns += htmx_urlpatterns
|
||||
@@ -1,9 +1,9 @@
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
from products.models import Product
|
||||
from mesas.models import Mesa
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def comandas(request):
|
||||
comandas = Comanda.objects.all()
|
||||
@@ -12,26 +12,19 @@ def comandas(request):
|
||||
|
||||
|
||||
|
||||
|
||||
def viewComanda(request):
|
||||
id = request.GET.get('parametro')
|
||||
comanda_id = int(id)
|
||||
comanda = Comanda.objects.get(id=comanda_id)
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||
products = Product.objects.all()
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
total += produto.product.price
|
||||
|
||||
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total})
|
||||
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products})
|
||||
|
||||
|
||||
def addProduct(request):
|
||||
pass
|
||||
# id = request.GET.get('parametro')
|
||||
# comanda_id = int(id)
|
||||
# comanda = Comanda.objects.get(id=comanda_id)
|
||||
# return render(request, 'addproduct.html', {'comanda': comanda})
|
||||
|
||||
|
||||
def createComanda(request):
|
||||
name = request.POST.get('name-comanda')
|
||||
|
||||
Reference in New Issue
Block a user