Skip to content

Instantly share code, notes, and snippets.

@Alireza2n
Forked from fabiocerqueira/mixins.py
Created April 23, 2018 09:43
Show Gist options
  • Save Alireza2n/e0ce7b467ca358d0be2e91f01212d468 to your computer and use it in GitHub Desktop.
Save Alireza2n/e0ce7b467ca358d0be2e91f01212d468 to your computer and use it in GitHub Desktop.
Success Message Mixin
from django.core.exceptions import ImproperlyConfigured
from django.contrib import messages
class SuccessMessageMixin(object):
success_message = None
def get_success_message(self):
if self.success_message:
message = self.success_message
else:
raise ImproperlyConfigured(
"No success message. Provide a success_message.")
return message
def form_valid(self, form):
response = super(SuccessMessageMixin, self).form_valid(form)
messages.success(self.request, self.get_success_message())
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment