Commit c0158a29 authored by Matthew Dizon's avatar Matthew Dizon

messages with CRUD functionality for food

parent 8ca31adb
......@@ -25,13 +25,17 @@
<div class="form-group">
<label for="name" > Date Created: </label>
<input type="date" class="form-control" id="date" name="date" required>
<label for="name"> Date Created: </label>
<input type="datetime-local" class="form-control" id="date" name="date" required>
</div>
<input type="hidden" name="message" value="Food created successfully">
<a href="{% url 'add_food' %}"><button type="submit" class="mt-3 btn btn-primary" >Add Food</button></a>
</form>
</div>
<a href="{% url 'view_foods' %}"><button class="btn btn-secondary mt-3">Back</button></a>
{% if message %}
<p class="mt-3 alert alert-danger" style="width: 75%"> {{message}}</p>
{% endif %}
{% endblock %}
......@@ -14,7 +14,10 @@
</ul>
</div>
<a href="{% url 'delete_food' food.pk %}"><button class="btn btn-danger my-4">Delete Food</button></a>
<a href="{% url 'update_food' food.pk %}"><button type="submit" class="btn btn-primary">Update Food</button></a>
<a href="{% url 'delete_food' food.pk %}"><button class="btn btn-danger my-4">Delete Food</button></a>
<a href="{% url 'view_foods' %}"><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
......@@ -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>
......
......@@ -56,7 +56,10 @@ def logout_view(request):
### Views for Order Model
def home(request):
orders = Order.objects.all()
if request.GET.get('message') == None:
context = {"orders": orders}
else:
context = {"orders": orders, 'message':request.GET.get('message')}
return render(request, 'Kiosk/home.html', context)
def view_order_details(request, pk):
......@@ -107,51 +110,31 @@ def add_order(request):
else:
return render(request, 'Kiosk/add_order.html', context)
### Views for Add Food
def add_food(request):
if(request.method=="POST"):
food_name = request.POST.get('food_name')
description = request.POST.get('description')
price = request.POST.get('price')
created_at = request.POST.get('date')
try:
Food.objects.create(
name = food_name,
description=description,
price=price,
created_at=created_at,
)
return redirect('view_foods')
except Exception as e:
message = e
print(message)
return render(request, 'Kiosk/add_food.html')
else:
return render(request, 'Kiosk/add_food.html')
def delete_order(request, pk):
Order.objects.filter(pk=pk).delete()
return redirect('home')
### Views for Food Model
def view_foods(request):
foods = Food.objects.all()
if request.GET.get('message') == None:
context = {"foods":foods}
else:
context = {"foods":foods, 'message':request.GET.get('message')}
return render(request, 'Kiosk/view_foods.html', context)
def view_food_details(request, pk):
food = get_object_or_404(Food, pk=pk)
context = {"food": food}
if request.GET.get('message') == None:
context = {"food":food}
else:
context = {"food":food, 'message':request.GET.get('message')}
return render(request, 'Kiosk/view_food_details.html', context)
def delete_food(request, pk):
Food.objects.filter(pk=pk).delete()
return redirect('view_foods')
message = "Food deleted successfully"
return redirect(f'/foods?message={message}')
def update_food(request, pk):
if(request.method=="POST"):
......@@ -160,12 +143,41 @@ def update_food(request, pk):
price = request.POST.get('price')
created_at = request.POST.get('date')
Food.objects.filter(pk=pk).update(name=name, description=description, price=price, created_at=created_at)
return redirect('view_food_details', pk=pk)
message = "Food updated successfully"
return redirect(f'/view_food_details/{pk}?message={message}', pk=pk)
else:
food = get_object_or_404(Food, pk=pk)
context = {"food": food}
return render(request, 'Kiosk/update_food.html', context)
def add_food(request):
if(request.method=="POST"):
food_name = request.POST.get('food_name')
description = request.POST.get('description')
price = request.POST.get('price')
created_at = request.POST.get('date')
try:
Food.objects.create(
name = food_name,
description=description,
price=price,
created_at=created_at,
)
message=request.POST.get('message')
return redirect(f"/foods?message={message}")
except Exception as e:
message = e
context = {'message':message}
return render(request, 'Kiosk/add_food.html', context)
else:
return render(request, 'Kiosk/add_food.html')
### Views for Customer Model
def view_customers(request):
customers = Customer.objects.all()
......
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