You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

19 lines
557 B

  1. from django.contrib import messages
  2. class SuccessMessageMixin(object):
  3. """
  4. Adds a success message on successful form submission.
  5. """
  6. success_message = ''
  7. def form_valid(self, form):
  8. response = super(SuccessMessageMixin, self).form_valid(form)
  9. success_message = self.get_success_message(form.cleaned_data)
  10. if success_message:
  11. messages.success(self.request, success_message)
  12. return response
  13. def get_success_message(self, cleaned_data):
  14. return self.success_message % cleaned_data