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 @@ ...@@ -77,7 +77,7 @@
{{item.Is_Expired}} {{item.Is_Expired}}
</th> </th>
<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> </th>
</tr> </tr>
......
...@@ -4,7 +4,7 @@ from django.conf.urls.static import static ...@@ -4,7 +4,7 @@ from django.conf.urls.static import static
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.urls import include, path from django.urls import include, path
from Breadcrumbs import views 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 = [ urlpatterns = [
url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'), url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'),
...@@ -16,6 +16,7 @@ urlpatterns = [ ...@@ -16,6 +16,7 @@ urlpatterns = [
path('fridge/<id>/delete', delete_product_type, name='product-type-delete'), 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'), 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>/add', add_item, name = 'add-item'),
path('fridge/<id>/<id2>/delete', delete_item, name = 'delete-item')
] ]
if settings.DEBUG: if settings.DEBUG:
......
...@@ -125,3 +125,15 @@ def add_item(request, id): ...@@ -125,3 +125,15 @@ def add_item(request, id):
form = AddItemForm() form = AddItemForm()
context['form'] = form context['form'] = form
return render(request,'add-item.html',context) 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