Skip to content

Commit

Permalink
Added functionality to delete a todo
Browse files Browse the repository at this point in the history
  • Loading branch information
shreys7 committed Dec 2, 2019
1 parent 7bb6ac2 commit d4867c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Binary file modified todoApp/db.sqlite3
Binary file not shown.
33 changes: 16 additions & 17 deletions todoApp/todos/templates/todos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@

{% block content %}

{% if todo_list %}
<div style="display: grid;">
<div class="row">
{% for todo in todo_list %}
<div class="col-sm-6">
<div class="card text-center">
<div class="card-body">
<h5 class="card-title">{{ todo.title }}</h5>
<p class="card-text">{{ todo.description }}</p>
<a href="{% url 'todos:edit' todo.id %}" class="btn btn-primary">Edit</a>
</div>
</div>
</div>
{% endfor %}
{% if todo_list %}
<div class="row">
{% for todo in todo_list %}
<div class="col-sm-6">
<div class="card text-center">
<div class="card-body">
<h5 class="card-title">{{ todo.title }}</h5>
<p class="card-text">{{ todo.description }}</p>
<a href="{% url 'todos:edit' todo.id %}" class="btn btn-primary">Edit</a>
<a href="{% url 'todos:delete' todo.id %}" class="btn btn-primary">Delete</a>
</div>
</div>
</div>
{% else %}
<p>No todos as of now</p>
{% endif %}
{% endfor %}
</div>
{% else %}
<p>No todos as of now</p>
{% endif %}
{% endblock %}
3 changes: 2 additions & 1 deletion todoApp/todos/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('<int:todo_id>/edit', views.edit, name='edit'),
path('<int:todo_id>/save', views.save, name='save')
path('<int:todo_id>/save', views.save, name='save'),
path('<int:todo_id>/delete', views.delete, name='delete')
]
5 changes: 5 additions & 0 deletions todoApp/todos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def save(request, todo_id):
todo.description = description

todo.save()
return redirect('todos:index')

def delete(request, todo_id):
todo = get_object_or_404(Todo, pk=todo_id)
todo.delete()

return redirect('todos:index')

Expand Down

0 comments on commit d4867c0

Please sign in to comment.