Added an edit feature. Base flavors and add ons (ingredients)

can now be updated.
The updated version moves to the bottom though.
Changed styling accordingly --made neater.
parent 5c38d050
......@@ -193,6 +193,20 @@ header {
cursor: pointer;
}
.edit {
border: none;
border-radius: 10px;
padding: 10px;
background-color: #A4BEF3;
}
.delete {
border: none;
border-radius: 10px;
padding: 10px;
background-color: #F87060;
}
a:link {
text-decoration: none;
border: none;
......
......@@ -30,8 +30,6 @@
<th>Options</th>
</tr>
<!-- TABLE ROWS WITH INFO -->
{% for ingredient in inventory %}
<tr>
......@@ -41,8 +39,8 @@
<td>{{ingredient.price_per_serving}}</td>
<td>{{ingredient.replenished_stock}}</td>
<td>
<button class="edit-value edit">Edit</button>
<button class="delete-value delete">Delete</button>
<button class="crud edit"><a class="crud-value edit" href="{% url 'update_ingredient' ingredient.ingredient_id %}">Edit</a></button>
<button class="crud-value delete">Delete</button>
</td>
</tr>
......
......@@ -29,8 +29,10 @@
<tr>
<td>{{bf.bf_name}}</td>
<td>
<button class="edit-value edit">Edit</button>
<button class="delete-value delete">Delete</button>
<button class="crud edit">
<a class="crud-value edit" href="{% url 'update_baseflavor' bf.bf_id %}">
Edit</a></button>
<button class="crud-value delete">Delete</button>
</td>
</tr>
{%endfor%}
......
......@@ -7,7 +7,7 @@
{% endblock %}
{% block content %}
<form action="/addBaseFlavor" method="POST" style="text-align:center">
<form action="" method="POST" style="text-align:center">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Submit">
......
......@@ -7,7 +7,7 @@
{% endblock %}
{% block content %}
<form action="/addingredient" method="POST" style="text-align:center">
<form action="" method="POST" style="text-align:center">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Submit">
......
......@@ -11,15 +11,6 @@ urlpatterns = [
path('schedule', schedule, name='schedule'),
path('report', report, name='report'),
#forms
path('addorder', addorder, name='addorder'),
path('additem', additem, name='additem'),
path('addcustomer', addcustomer, name='addcustomer'),
path('addingredient', addingredient, name='addingredient'),
path('addBaseFlavor', addbaseflavor, name='addBaseFlavor'),
path('addinventory', addinventory, name='addinventory'),
#queries
path('manager_query', manager_query, name='manager_query'),
path('week_query', week_query, name='week_query'),
......@@ -32,4 +23,19 @@ urlpatterns = [
path('receipt', receipt, name='receipt'),
path('orderslip', orderSlip, name='orderslip'),
#forms
path('addorder', addorder, name='addorder'),
path('additem', additem, name='additem'),
path('addcustomer', addcustomer, name='addcustomer'),
# CRUD - FOR ADD ONS
path('addingredient', addingredient, name='addingredient'),
path('update_ingredient/<str:pk>/', updateIngredient, name='update_ingredient'),
# CRUD - FOR BASE FLAVORS
path('addBaseFlavor', addbaseflavor, name='addBaseFlavor'),
path('update_baseflavor/<str:pk>/', updateBaseFlavor, name='update_baseflavor'),
path('addinventory', addinventory, name='addinventory'),
]
......@@ -42,8 +42,6 @@ def baseFlavors(request):
}
return render(request, "blizzardblast/templates/filtered_views/baseFlavors.html", contexts)
def schedule(request):
all_values = EmployeeRole.objects.all()
return render(request,
......@@ -137,14 +135,40 @@ def addingredient(request):
return redirect('/inventory')
return render(request, "blizzardblast/templates/forms/addingredient.html", context)
def updateIngredient(request,pk):
ingredient = Ingredient.objects.get(ingredient_id=pk)
form = AddIngredient(instance=ingredient)
context = {'form':form}
# this handles updating the values in the form
if request.method == 'POST':
form = AddIngredient(request.POST, instance=ingredient)
if form.is_valid():
form.save()
return redirect('/inventory')
return render(request, "blizzardblast/templates/forms/addingredient.html", context)
def addbaseflavor(request):
form = AddBaseFlavor()
context = {'form':form}
if request.method == 'POST':
form = AddBaseFlavor(request.POST)
if form.is_valid():
form.save()
return redirect('/inventory')
return render(request, "blizzardblast/templates/forms/addBaseFlavor.html", context)
def updateBaseFlavor(request,pk):
bf = BaseFlavor.objects.get(bf_id=pk)
form = AddBaseFlavor(instance=bf)
context = {'form':form}
# this handles updating the values in the form
if request.method == 'POST':
form = AddBaseFlavor(request.POST, instance=bf)
if form.is_valid():
form.save()
return redirect('/inventory')
return render(request, "blizzardblast/templates/forms/addBaseFlavor.html", context)
def addinventory(request):
......
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