Commit 3a6ec072 authored by James Esguerra's avatar James Esguerra

Added edit button to list of items to redirect to edit view

parent c8042de8
...@@ -9,5 +9,6 @@ urlpatterns = [ ...@@ -9,5 +9,6 @@ urlpatterns = [
path('add_key/', views.ShowAddKey, name='add_key'), path('add_key/', views.ShowAddKey, name='add_key'),
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('today/', views.ShowToday, name='today'), path('today/', views.ShowToday, name='today'),
] ]
...@@ -54,6 +54,19 @@ def ShowAddItemTW(request): ...@@ -54,6 +54,19 @@ def ShowAddItemTW(request):
return render(request, 'add_itemTW.html', {'form': form}) return render(request, 'add_itemTW.html', {'form': form})
def ShowEditItemTW(request, pk):
item = ItemsThisWeek.objects.get(id=pk)
form = ItemsThisWeekForm(instance=item)
if request.method == 'POST':
form = ItemsThisWeekForm(request.POST, instance=item)
if form.is_valid():
form.save()
return redirect('this_week')
return render(request, 'edit_itemTW.html', {'form': form})
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 %}
{{ form }}
<input type='submit' name='Submit' value='Save'>
</form>
{% endblock %}
...@@ -9,11 +9,13 @@ ...@@ -9,11 +9,13 @@
<div id='this_week'> <div id='this_week'>
<h2>04.12.MON - 04.18.SUN</h2> <h2>04.12.MON - 04.18.SUN</h2>
<br>
{% for item in item_list %} {% for item in item_list %}
<p><b>{{ item.key_type }}:</b> {{ item.details }} </p> <p>
<b>{{ item.key_type }}:</b> {{ item.details }}
<a href='{% url 'edit_itemTW' item.pk %}'><button type='button'> Edit </button></a>
</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>
</div> </div>
......
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