Opened 7 years ago

Closed 7 years ago

#29064 closed New feature (duplicate)

SuccessMessageMixin delete support

Reported by: Éttore Leandro Tognoli Owned by: nobody
Component: contrib.messages Version: 2.0
Severity: Normal Keywords: delete, message, SuccessMessageMixin, DeleteView, generic view
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I want to show a message when I delete some object using the SuccessMessageMixin, but it doesn't work because the DeleteView doesn't have a form_valid method.
I think it would be nice if django had native support for this.

I wrote something like this in my personal project:

from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.forms import model_to_dict

class SuccessMessageMixinWithDeleteSupport(SuccessMessageMixin):
    def delete_form_valid(self, object):
        success_message = self.get_success_message(model_to_dict(object))
        if success_message:
            messages.success(self.request, success_message)

    def delete(self, *args, **kwargs):
        object = self.get_object()
        result = super().delete(*args, **kwargs)
        self.delete_form_valid(object)
        return result

Change History (1)

comment:1 by Simon Charette, 7 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #21936.

Note: See TracTickets for help on using tickets.
Back to Top