From 852def01d291b3cb301fdcc23106a916f581d023 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Wed, 12 Aug 2020 20:35:49 +0200 Subject: [PATCH] Added success and error messages to CreatePlaceView. --- lostplaces/lostplaces_app/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index 956d89c..970a7d6 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -107,11 +107,19 @@ class PlaceCreateView(IsAuthenticated, View): kwargs_to_pass = { 'pk': place.pk } + + messages.success( + self.request, 'Successfully created place.') return redirect(reverse_lazy('place_detail', kwargs=kwargs_to_pass)) + else: context = { 'form': form_place } + + # Usually the browser should have checked the form before sending. + messages.error( + self.request, 'Please fill in all required fields.') return render(request, 'place/place_create.html', context) def _apply_multipart_image_upload(self, files, place, submitter):