Simplified UpdatePlace success message using Mixin.

This commit is contained in:
Marcus Scholz 2020-08-12 20:52:17 +02:00
parent 0cf482dc5c
commit 0b3aff1d1d

View File

@ -70,14 +70,13 @@ class HomeView(View):
} }
return render(request, 'home.html', context) return render(request, 'home.html', context)
class PlaceUpdateView(IsAuthenticated, IsSubmitter, UpdateView): class PlaceUpdateView(IsAuthenticated, IsSubmitter, SuccessMessageMixin, UpdateView):
template_name = 'place/place_update.html' template_name = 'place/place_update.html'
model = Place model = Place
form_class = PlaceForm form_class = PlaceForm
success_message = 'Successfully updated place.'
def get_success_url(self): def get_success_url(self):
messages.success(
self.request, 'Successfully updated place.')
return reverse_lazy('place_detail', kwargs={'pk':self.get_object().pk}) return reverse_lazy('place_detail', kwargs={'pk':self.get_object().pk})
class PlaceCreateView(IsAuthenticated, View): class PlaceCreateView(IsAuthenticated, View):
@ -136,8 +135,9 @@ class PlaceCreateView(IsAuthenticated, View):
) )
place_image.save() place_image.save()
class PlaceDeleteView(IsAuthenticated, IsSubmitter, DeleteView): class PlaceDeleteView(IsAuthenticated, IsSubmitter, SuccessMessageMixin, DeleteView):
template_name = 'place/place_delete.html' template_name = 'place/place_delete.html'
model = Place model = Place
success_url = reverse_lazy('place_list') success_url = reverse_lazy('place_list')
success_message = 'Successfully deleted place.'