Commit 39d0a51f authored by James Esguerra's avatar James Esguerra

Added delete button to list of items TW to redirect to delete view

parent 3a6ec072
...@@ -10,5 +10,6 @@ urlpatterns = [ ...@@ -10,5 +10,6 @@ urlpatterns = [
path('this_week/', views.ShowThisWeek, name='this_week'), path('this_week/', views.ShowThisWeek, name='this_week'),
path('add_itemTW/', views.ShowAddItemTW, name='add_itemTW'), path('add_itemTW/', views.ShowAddItemTW, name='add_itemTW'),
path('edit_itemTW/<int:pk>', views.ShowEditItemTW, name='edit_itemTW'), path('edit_itemTW/<int:pk>', views.ShowEditItemTW, name='edit_itemTW'),
path('delete_itemTW/<int:pk>', views.ShowDeleteItemTW, name='delete_itemTW'),
path('today/', views.ShowToday, name='today'), path('today/', views.ShowToday, name='today'),
] ]
...@@ -67,6 +67,15 @@ def ShowEditItemTW(request, pk): ...@@ -67,6 +67,15 @@ def ShowEditItemTW(request, pk):
return render(request, 'edit_itemTW.html', {'form': form}) return render(request, 'edit_itemTW.html', {'form': form})
def ShowDeleteItemTW(request, pk):
if request.method == 'POST':
item = ItemsThisWeek.objects.get(id=pk)
item.delete()
return redirect('this_week')
return render(request, 'delete_itemTW.html')
def ShowToday(request): def ShowToday(request):
my_date = datetime.datetime.now() my_date = datetime.datetime.now()
return render(request, 'today.html', {'my_date': my_date}) return render(request, 'today.html', {'my_date': my_date})
{% extends 'base.html' %}
{% load static %}
{% block title %} Key {% endblock %}
{% block header %} Key {% endblock %}
{% block content %}
<form action='' method='POST'>
{% csrf_token %}
<input type='submit' name='Submit' value='Yes'>
<a href='{% url 'this_week' %}'><button type='button'> No </button></a>
</form>
{% endblock %}
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<p> <p>
<b>{{ item.key_type }}:</b> {{ item.details }} <b>{{ item.key_type }}:</b> {{ item.details }}
<a href='{% url 'edit_itemTW' item.pk %}'><button type='button'> Edit </button></a> <a href='{% url 'edit_itemTW' item.pk %}'><button type='button'> Edit </button></a>
<a href='{% url 'delete_itemTW' item.pk %}'><button type='button'> X </button></a>
</p> </p>
{% endfor %} {% endfor %}
<a href='{% url 'add_itemTW' %}'><button type='button'> Add Item </button></a> <a href='{% url 'add_itemTW' %}'><button type='button'> Add Item </button></a>
......
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