I've got FormView
that redirect to a previous page if the form was valid. That's works fine but how can I tell a user that the information has been posted? I want him to see a success message in a modal window after redirect.
I've tried to do it through request.session
in get_success_url
but it doesn't fit to my goals because a user can submit the form multiple times. So how can I return any message with redirect in get_success_url
in FormView
?
My FormView
class CatPhotoUploadFormView(FormView):
template_name = 'blank.html'
form_class = CatPhotoForm
def get_success_url(self):
self.request.session['success_message'] = 'Everything is fine'
return reverse('cat:detail_cat', args=(self.kwargs['pk'],))
def form_valid(self, form):
cat = Cat.objects.filter(id__exact=self.kwargs['pk'])
for each in form.cleaned_data['attachments']:
print('****', each, '****', type(each))
Photo.objects.create(photo_path=each, photo_author=self.request.user, photo_cat = cat[0])
return super(CatPhotoUploadFormView, self).form_valid(form)