create comanda | detalhe comanda

This commit is contained in:
2024-12-12 21:33:04 -03:00
parent 2f84ca97c3
commit a3bb7bb674
15 changed files with 284 additions and 21 deletions

View File

@@ -1,12 +1,14 @@
from django.shortcuts import render, redirect
from comandas.models import Comanda
from comandas.models import Comanda, ProductComanda
from mesas.models import Mesa
# Create your views here.
def comandas(request):
comandas = Comanda.objects.all()
return render(request, 'comandas.html', {'comandas': comandas})
mesas = Mesa.objects.all()
return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
@@ -15,5 +17,27 @@ 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)
total = 0
for produto in consumo:
total += produto.product.price
return render(request, 'viewcomanda.html', {'comanda': comanda})
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total})
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')
mesa_id = int(request.POST.get('select-mesa')[0])
mesa = Mesa.objects.get(id=mesa_id)
comanda = Comanda(name=name, mesa=mesa)
comanda.save()
return redirect('comandas')