Add support for deleting URLs

parent fb2e8c4d
......@@ -11,4 +11,9 @@
<li>Followed: {{ url.used }} time(s).</li>
</ul>
<p>
<a href="{% url 'delete' url.id %}" role="button"
class="btn btn-danger">Delete</a>
</p>
{% endblock %}
......@@ -8,4 +8,5 @@ urlpatterns = [
url(r'^url=(?P<url_id>[0-9]+)$', views.details, name='details'),
url(r'^new$', views.new, name='new'),
url(r'^generate$', views.generate, name='generate'),
url(r'^delete=(?P<url_id>[0-9]+)$', views.delete, name='delete'),
]
......@@ -39,3 +39,9 @@ def generate(request):
u = Url(target=request.POST['target'], user=request.user)
u.save()
return HttpResponseRedirect(reverse('index'))
@login_required
def delete(request, url_id):
u = get_object_or_404(Url, id=url_id, user__exact=request.user)
u.delete()
return HttpResponseRedirect(reverse('index'))
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