mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
create views comandas
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,5 +9,8 @@ class Mesa(models.Model):
|
||||
location = models.CharField(max_length=255, null=True, blank=True)
|
||||
active = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
# Foreign Key to Comandas model (assuming it exists)
|
||||
# comanda = models.ForeignKey('Comandas', on_delete=models.DO_NOTHING, db_column='id_mesa')
|
||||
@@ -18,7 +18,21 @@ RRB&C - Mesas
|
||||
|
||||
{% for mesa in mesas %}
|
||||
|
||||
<div class="card">{{mesa.name}}</div>
|
||||
<div class="card"
|
||||
{% if mesa.active == True %}
|
||||
style="background-color: indianred;"
|
||||
{% endif %}
|
||||
>{{mesa.name}}
|
||||
|
||||
|
||||
<form action="{% url 'onOffmesa' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="id-mesa" value="{{ mesa.id }}">
|
||||
<button type="submit">On/Off</button>
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.mesas, name='mesas'),
|
||||
path('onOffmesa/', views.onOffmesa, name='onOffmesa'),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render,redirect
|
||||
|
||||
from mesas.models import Mesa
|
||||
|
||||
@@ -6,4 +6,14 @@ from mesas.models import Mesa
|
||||
|
||||
def mesas(request):
|
||||
mesas = Mesa.objects.all()
|
||||
return render(request, 'mesas.html', {'mesas': mesas})
|
||||
return render(request, 'mesas.html', {'mesas': mesas})
|
||||
|
||||
|
||||
|
||||
def onOffmesa(request):
|
||||
id = request.POST.get('id-mesa')
|
||||
mesa_id = int(id)
|
||||
mesa = Mesa.objects.get(id=mesa_id)
|
||||
mesa.active = not mesa.active
|
||||
mesa.save()
|
||||
return redirect('mesas')
|
||||
Reference in New Issue
Block a user