Opened 15 years ago

Closed 14 years ago

Last modified 13 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: dev
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: no UI/UX: no

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 15 years ago.
patch to add ModelAdmin.delete_model() in contrib.admin.options.py
delete_model@11970.diff (3.5 KB ) - added by Florian Apolloner 15 years ago.
delete_model@14387.diff (3.2 KB ) - added by Florian Apolloner 14 years ago.
delete_model.diff (6.4 KB ) - added by Florian Apolloner 14 years ago.

Download all attachments as: .zip

Change History (19)

by thomas, 15 years ago

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

comment:1 by thomas, 15 years ago

Version: 1.0SVN

comment:2 by shadfc, 15 years ago

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 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

in reply to:  2 comment:4 by anonymous, 15 years ago

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…)

by Florian Apolloner, 15 years ago

Attachment: delete_model@11970.diff added

comment:5 by Florian Apolloner, 15 years ago

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 by Sebastian Noack, 14 years ago

See also #13708

by Florian Apolloner, 14 years ago

Attachment: delete_model@14387.diff added

comment:7 by Florian Apolloner, 14 years ago

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 by steph, 14 years ago

Keywords: sprintnov13 added

comment:9 by Florian Apolloner, 14 years ago

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

by Florian Apolloner, 14 years ago

Attachment: delete_model.diff added

comment:10 by Alex Gaynor, 14 years ago

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 by Divad, 14 years ago

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 by Julien Phalip, 14 years ago

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 by Divad <david@…>, 14 years ago

Resolution: fixed
Status: closedreopened

Thanks julien, I will reopen.

comment:14 by Florian Apolloner, 14 years ago

Resolution: fixed
Status: reopenedclosed

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

comment:15 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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