Commit 2c6e3121 authored by Julia Santos's avatar Julia Santos

Users can now delete items under a specific product type

parent e04ba2de
......@@ -77,7 +77,7 @@
{{item.Is_Expired}}
</th>
<th>
<a href='http://127.0.0.1:8000/fridge/{{item.Item_ID}}/delete'>Delete?</a>
<a href='http://127.0.0.1:8000/fridge/{{item.Product_ID}}/{{item.Item_ID}}/delete'>Delete?</a>
</th>
</tr>
......
......@@ -4,7 +4,7 @@ from django.conf.urls.static import static
from django.views.generic import TemplateView
from django.urls import include, path
from Breadcrumbs import views
from .views import ProductListViewName, ProductListViewCategory, add_product_type, delete_product_type, ItemViewPDate, add_item
from .views import ProductListViewName, ProductListViewCategory, add_product_type, delete_product_type, ItemViewPDate, add_item, delete_item
urlpatterns = [
url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'),
......@@ -16,6 +16,7 @@ urlpatterns = [
path('fridge/<id>/delete', delete_product_type, name='product-type-delete'),
url(r'^fridge/(?P<Product_ID>\d+)/$', ItemViewPDate.as_view(), name='item-purchase-date-view'),
path('fridge/<id>/add', add_item, name = 'add-item'),
path('fridge/<id>/<id2>/delete', delete_item, name = 'delete-item')
]
if settings.DEBUG:
......
......@@ -125,3 +125,15 @@ def add_item(request, id):
form = AddItemForm()
context['form'] = form
return render(request,'add-item.html',context)
def delete_item(request,id,id2):
context = {}
item = get_object_or_404(Item,Item_ID = id2)
prod_type = item.Product_ID
if request.method=="POST":
item.delete()
return HttpResponseRedirect("/fridge/" + str(prod_type))
return render(request, 'product-type-confirm-delete.html', context)
\ No newline at end of file
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