From 0b3aff1d1d3153e618cc78e95cf938580122535c Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Wed, 12 Aug 2020 20:52:17 +0200 Subject: [PATCH] Simplified UpdatePlace success message using Mixin. --- lostplaces/lostplaces_app/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index 3f20e5c..d364f9a 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -70,14 +70,13 @@ class HomeView(View): } return render(request, 'home.html', context) -class PlaceUpdateView(IsAuthenticated, IsSubmitter, UpdateView): +class PlaceUpdateView(IsAuthenticated, IsSubmitter, SuccessMessageMixin, UpdateView): template_name = 'place/place_update.html' model = Place form_class = PlaceForm + success_message = 'Successfully updated place.' def get_success_url(self): - messages.success( - self.request, 'Successfully updated place.') return reverse_lazy('place_detail', kwargs={'pk':self.get_object().pk}) class PlaceCreateView(IsAuthenticated, View): @@ -136,8 +135,9 @@ class PlaceCreateView(IsAuthenticated, View): ) place_image.save() -class PlaceDeleteView(IsAuthenticated, IsSubmitter, DeleteView): +class PlaceDeleteView(IsAuthenticated, IsSubmitter, SuccessMessageMixin, DeleteView): template_name = 'place/place_delete.html' model = Place success_url = reverse_lazy('place_list') + success_message = 'Successfully deleted place.' \ No newline at end of file