From 8b01bbb2ce9395266392c7f6e207bf0845e07cf3 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Wed, 12 Aug 2020 11:28:11 +0200 Subject: [PATCH] Added named cancel button that redirects to success_url. --- .../lostplaces_app/templates/place/place_delete.html | 5 +++-- lostplaces/lostplaces_app/views.py | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lostplaces/lostplaces_app/templates/place/place_delete.html b/lostplaces/lostplaces_app/templates/place/place_delete.html index 246fa69..ee3ef9a 100644 --- a/lostplaces/lostplaces_app/templates/place/place_delete.html +++ b/lostplaces/lostplaces_app/templates/place/place_delete.html @@ -12,9 +12,10 @@

Are you sure you want to delete "{{place.name}}"?

- + +
-{% endblock maincontent %} \ No newline at end of file +{% endblock maincontent %} diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index ab0b67b..90486ac 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -98,6 +98,10 @@ class PlaceCreateView(View): class PlaceDeleteView(DeleteView): template_name = 'place/place_delete.html' model = Place + success_url = reverse_lazy('place_list') - def get_success_url(self): - return reverse_lazy('place_list') + def post(self, request, *args, **kwargs): + if "cancel" in request.POST: + return redirect(self.success_url) + else: + return super(PlaceDeleteView, self).post(request, *args, **kwargs)