Commit 7cc208d9 authored by James Esguerra's avatar James Esguerra

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

parent 2b168da7
......@@ -13,4 +13,5 @@ urlpatterns = [
path('delete_itemTW/<int:pk>', views.ShowDeleteItemTW, name='delete_itemTW'),
path('today/', views.ShowToday, name='today'),
path('add_itemT', views.ShowAddItemT, name='add_itemT'),
path('edit_itemT/<int:pk>', views.ShowEditItemT, name='edit_itemT'),
]
......@@ -90,3 +90,16 @@ def ShowAddItemT(request):
return redirect('today')
return render(request, 'add_itemT.html', {'form': form})
def ShowEditItemT(request, pk):
item = ItemsToday.objects.get(id=pk)
form = ItemsTodayForm(instance=item)
if request.method == 'POST':
form = ItemsTodayForm(request.POST, instance=item)
if form.is_valid():
form.save()
return redirect('today')
return render(request, 'edit_itemT.html', {'form': form})
{% 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 %}
......@@ -13,6 +13,7 @@
{% for item in item_list %}
<p>
<b>{{ item.key_type }}:</b> {{ item.details }}
<a href='{% url 'edit_itemT' item.pk %}'><button type='button'> Edit </button></a>
<p>
{% endfor %}
<a href='{% url 'add_itemT' %}'><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