Fakultas Ilmu Komputer UI

Commit 86edea60 authored by Luthfi Dzaky Saifuddin's avatar Luthfi Dzaky Saifuddin
Browse files

[GREEN] add implementation to delete item

parent 46f07944
Pipeline #27499 passed with stages
in 9 minutes and 53 seconds
......@@ -5,12 +5,21 @@
{% block form_action %}{% url 'view_list' list.id %}{% endblock %}
{% block table %}
<table id="id_list_table" class="table">
<tr><th>My To Do List</th>
<th>Created Date</th></tr>
{% for item in list.item_set.all %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td>
<td>{{ item.created_date }}</td></tr>
{% endfor %}
</table>
<table id="id_list_table" class="table">
<tr>
<th>My To Do List</th>
<th>Created Date</th>
<th></th>
</tr>
{% for item in list.item_set.all %}
<tr>
<td>{{ forloop.counter }}: {{ item.text }}</td>
<td>{{ item.created_date }}</td>
<td><a href="{% url 'delete_item' list.id item.id %}" class="delete-item">
<div data-id="{{ data.id }}">&#10006</div>
</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
\ No newline at end of file
......@@ -20,4 +20,5 @@ urlpatterns = [
url(r'^new$', views.new_list, name='new_list'),
url(r'^(\d+)/$', views.view_list, name='view_list'),
url(r'^(\d+)/add_item$', views.add_item, name='add_item'),
url(r'^(\d+)/delete_item/(\d+)$', views.delete_item, name='delete_item'),
]
......@@ -38,6 +38,12 @@ def add_item(request, list_id):
Item.objects.create(text=request.POST['item_text'], list=list_)
return redirect(f'/lists/{list_.id}/')
def delete_item(request, list_id, item_id):
item = Item.objects.get(id=item_id)
item.delete()
list_ = List.objects.get(id=list_id)
return redirect(f'/lists/{list_.id}/')
def message_todo(list_):
if (list_.item_set.count() == 0):
return "yey, waktunya berlibur"
......
Supports Markdown
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