Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718
  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