Opened 8 years ago

Closed 6 years ago

Last modified 5 years ago

#11108 closed (fixed)

add a ModelAdmin.delete_model method, similar to ModelAdmin.save_model (+patch)

Reported by: thomas Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: sprintnov13
Cc: jay.wineinger@…, Florian Apolloner Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

When we delete an object, it could be usefull to have the "request" attribute. For example to know "how is doing this delete", as shown as the exemple with save_model (http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#modeladmin-methods).

My very little patch creates a ModelAdmin.delete_model(self, request, obj) method, one can override in admin.py.

I use it in a custom log system, where I log all details of all modifications of a object, with the "modifier" who make the modification (request.user). I can log creations and modifications with save_model, now I can log delete() too.

Thanks.

Attachments (4)

contrib-admin-options-py.diff (893 bytes) - added by thomas 8 years ago.
patch to add ModelAdmin.delete_model() in contrib.admin.options.py
delete_model@11970.diff (3.5 KB) - added by Florian Apolloner 7 years ago.
delete_model@14387.diff (3.2 KB) - added by Florian Apolloner 6 years ago.
delete_model.diff (6.4 KB) - added by Florian Apolloner 6 years ago.

Download all attachments as: .zip

Change History (19)

Changed 8 years ago by thomas

patch to add ModelAdmin.delete_model() in contrib.admin.options.py

comment:1 Changed 8 years ago by thomas

Version: 1.0SVN

comment:2 Changed 8 years ago by shadfc

Cc: jay.wineinger@… added
Needs documentation: set
Needs tests: set
Patch needs improvement: set

from the trac-view of the patch above

 	1022	            self.delete_model(request, obj) 
1017	1023	 
1018	1024	            self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') %...

Slight bug -- if you don't actually delete the object, the message will still show. Similar bug with the delete log message?

comment:3 Changed 7 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

comment:4 in reply to:  2 Changed 7 years ago by anonymous

Cc: Florian Apolloner added

Replying to shadfc:

Slight bug -- if you don't actually delete the object, the message will still show. Similar bug with the delete log message?

not really imo, delete_model is expected to delete the object, so I guess this will fall under documentation (remember you confirmed that you really want to delete it already…)

Changed 7 years ago by Florian Apolloner

Attachment: delete_model@11970.diff added

comment:5 Changed 7 years ago by Florian Apolloner

Needs documentation: unset
Patch needs improvement: unset

My testsuite is currently failing, but I guess that cause my settings.py isn't configured for multidb tests

comment:6 Changed 6 years ago by Sebastian Noack

See also #13708

Changed 6 years ago by Florian Apolloner

Attachment: delete_model@14387.diff added

comment:7 Changed 6 years ago by Florian Apolloner

milestone: 1.3

Updated the patch to apply cleanly on current trunk, do we really need tests here? the delete functionality should already be covered by the view tests?

comment:8 Changed 6 years ago by steph

Keywords: sprintnov13 added

comment:9 Changed 6 years ago by Florian Apolloner

New patch with tests for 'save_model' and 'delete_model'

Changed 6 years ago by Florian Apolloner

Attachment: delete_model.diff added

comment:10 Changed 6 years ago by Alex Gaynor

Resolution: fixed
Status: newclosed

(In [14673]) Fixed #11108 -- added ModelAdmin.delete_model, a hook with which to perform custom pre-post delete behavior. Thanks to Florian Apolloner for the patch.

comment:11 Changed 6 years ago by Divad

This should also include this change in actions.py:

47c47
<                 modeladmin.delete_model(request,obj)
---
>             queryset.delete()

To have the same result using delete_selected from actions.

comment:12 Changed 6 years ago by Julien Phalip

Divad, you might want to open a new ticket if you'd like to make more changes. This ticket is closed, so your idea is likely to be forgotten if it stays here.

comment:13 Changed 6 years ago by Divad <david@…>

Resolution: fixed
Status: closedreopened

Thanks julien, I will reopen.

comment:14 Changed 6 years ago by Florian Apolloner

Resolution: fixed
Status: reopenedclosed

You should open a new ticket, not reopen old ones…

comment:15 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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