Commit 645ee339 authored by Matthew Dizon's avatar Matthew Dizon

messages with CRUD functionality for order

parent 6c8c6912
......@@ -39,6 +39,11 @@
.active {
color: #23272B;
}
label {
color: #8AB4F8;
font-weight:bold;
}
</style>
<body>
......
......@@ -10,6 +10,10 @@
</div>
</section>
{% if message %}
<p class="mt-3 alert alert-success"> {{message}}</p>
{% endif %}
<div class="col-12">
<table class="table table-striped">
<thead>
......
......@@ -18,4 +18,7 @@
<a href="{% url 'update_order' order.pk %}"><button class="btn btn-primary">Update Order</button></a>
<a href="{% url 'delete_order' order.pk %}"><button class="btn btn-danger my-4">Delete Order</button></a>
<a href="{% url 'home' %}"><button class="btn btn-secondary">Back</button></a>
{% if message %}
<p class="mt-3 alert alert-success" style="width: 75%"> {{message}}</p>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -64,7 +64,10 @@ def home(request):
def view_order_details(request, pk):
order = get_object_or_404(Order, pk=pk)
if request.GET.get('message') == None:
context = {"order": order}
else:
context = {"order": order, 'message':request.GET.get('message')}
return render(request, 'Kiosk/view_order_details.html', context)
def update_order(request, pk):
......@@ -72,7 +75,8 @@ def update_order(request, pk):
qty = request.POST.get('qty')
payment_mode = request.POST.get('payment_mode')
Order.objects.filter(pk=pk).update(qty=qty, payment_mode=payment_mode)
return redirect('view_order_details', pk=pk)
message = "Order updated successfully"
return redirect(f'/view_order_details/{pk}?message={message}', pk=pk)
else:
order = get_object_or_404(Order, pk=pk)
context = {"order": order}
......@@ -100,7 +104,8 @@ def add_order(request):
payment_mode = payment_mode
)
return redirect('home')
message= "Order created successfully"
return redirect(f"/home?message={message}")
except Exception as e:
message = e
......@@ -112,7 +117,8 @@ def add_order(request):
def delete_order(request, pk):
Order.objects.filter(pk=pk).delete()
return redirect('home')
message = "Order deleted successfully"
return redirect(f'/home?message={message}')
### Views for Food Model
def view_foods(request):
......@@ -142,9 +148,17 @@ def update_food(request, pk):
description = request.POST.get('description')
price = request.POST.get('price')
created_at = request.POST.get('date')
try:
Food.objects.filter(pk=pk).update(name=name, description=description, price=price, created_at=created_at)
message = "Food updated successfully"
return redirect(f'/view_food_details/{pk}?message={message}', pk=pk)
except Exception as e:
message = f"Food name '{name}' already exists"
food = get_object_or_404(Food, pk=pk)
context = {"food": food, "message": message}
return render(request, 'Kiosk/update_food.html', context)
else:
food = get_object_or_404(Food, pk=pk)
context = {"food": food}
......@@ -165,7 +179,7 @@ def add_food(request):
created_at=created_at,
)
message=request.POST.get('message')
message="Food created successfully"
return redirect(f"/foods?message={message}")
except Exception as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment