Opened 4 years ago
Closed 4 years ago
#32514 closed New feature (duplicate)
A mixin for success messages when an object is deleted
Reported by: | Willem Van Onsem | Owned by: | nobody |
---|---|---|---|
Component: | contrib.messages | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A case that is not covered by the SuccessMessageMixin
is to add a successmessage when the object is removed.
It might be a good idea to create a mixin that will send a success message in case of a successful DELETE/POST request. This could look like:
diff --git a/django/contrib/messages/views.py b/django/contrib/messages/views.py index eaa1bee9d5..ac938f7845 100644 --- a/django/contrib/messages/views.py +++ b/django/contrib/messages/views.py @@ -16,3 +16,21 @@ class SuccessMessageMixin: def get_success_message(self, cleaned_data): return self.success_message % cleaned_data + + +class SuccessDeleteMessageMixin: + """ + Add a success message on a successful DELETE request (and sometimes POST request + if this will make trigger delete). + """ + success_message = '' + + def delete(self, *args, **kwargs): + response = super().delete(*args, **kwargs) + success_message = self.get_success_message() + if success_message: + messages.success(self.request, success_message) + return response + + def get_success_message(self): + return self.success_message
Attachments (1)
Note:
See TracTickets
for help on using tickets.
patch to apply