Django Message Mixin

Django -- Posted on May 26, 2019

Django message mixin to use with createview, updateview

              
                class MessageMixin:
    def form_valid(self, form):
        form.save()
        messages.success(
            self.request, 'Your {} was proccesed successfully!'.format(
                self.model.__name__))
        return super().form_valid(form)

    def form_invalid(self, form):
        messages.error(
            self.request, 'error occured for {}'.format(
                self.model.__name__))
        return super().form_invalid(form)
                  
   
            

Related Posts