Opened 6 years ago

Closed 5 years ago

Last modified 4 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@…, apollo13 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 6 years ago.
patch to add ModelAdmin.delete_model() in contrib.admin.options.py
delete_model@11970.diff (3.5 KB) - added by apollo13 6 years ago.
delete_model@14387.diff (3.2 KB) - added by apollo13 5 years ago.
delete_model.diff (6.4 KB) - added by apollo13 5 years ago.

Download all attachments as: .zip

Change History (19)

Changed 6 years ago by thomas

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

comment:1 Changed 6 years ago by thomas

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.0 to SVN

comment:2 follow-up: Changed 6 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 6 years ago by Alex

  • Triage Stage changed from Unreviewed to Accepted

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

  • Cc apollo13 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 6 years ago by apollo13

comment:5 Changed 6 years ago by apollo13

  • 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 5 years ago by sebastian_noack

See also #13708

Changed 5 years ago by apollo13

comment:7 Changed 5 years ago by apollo13

  • milestone set to 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 5 years ago by steph

  • Keywords sprintnov13 added

comment:9 Changed 5 years ago by apollo13

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

Changed 5 years ago by apollo13

comment:10 Changed 5 years ago by Alex

  • Resolution set to fixed
  • Status changed from new to closed

(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 5 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 5 years ago by julien

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

  • Resolution fixed deleted
  • Status changed from closed to reopened

Thanks julien, I will reopen.

comment:14 Changed 5 years ago by apollo13

  • Resolution set to fixed
  • Status changed from reopened to closed

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

comment:15 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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