Opened 6 years ago

Last modified 5 months ago

#17962 assigned New feature

Add ModelAdmin.get_deleted_objects() hook

Reported by: Chris Wilson Owned by: Rebecca Smith
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Chris Wilson, Rebecca Smith Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I want to increase control over who can delete what objects using the admin interface.

delete_view calls has_delete_permission(), which is fine, but then it calls get_deleted_objects() from django.contrib.admin.util.

This is very hard to override without monkey-patching get_deleted_objects(), because it requires replacing the whole of delete_view just to change one line.

I propose calling a member method get_deleted_objects(), which by default just calls the one from util, to make it easy to override this behaviour.

I've attached a patch without tests, because the existing tests should check that this doesn't break anything.

Attachments (1)

options.patch (1.7 KB) - added by Chris Wilson 6 years ago.
Patch to add get_deleted_objects() hook to ModelAdmin

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by Chris Wilson

Attachment: options.patch added

Patch to add get_deleted_objects() hook to ModelAdmin

comment:1 Changed 6 years ago by Luke Plant

Component: Uncategorizedcontrib.admin
Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

I'm accepting, but marking as 'needs tests', because although it is a simple change, we need tests that check that ModelAdmin.get_deleted_objects() is actually used. This has been our policy with other simple changes, like #14206 for ModelAdmin.get_list_display, and ListView.get_paginator.

comment:2 Changed 10 months ago by Rebecca Smith

Owner: changed from nobody to Rebecca Smith
Status: newassigned

comment:3 Changed 10 months ago by Rebecca Smith

Needs documentation: unset
Needs tests: unset

I have added PR #8267 to update the previously submitted patch and use the new ModelAdmin method in the default delete_selected action as well as delete_view.

comment:4 Changed 7 months ago by Tim Graham

Summary: Django Admin delete_view could benefit from extension pointsAdd ModelAdmin.get_deleted_objects() hook

comment:5 Changed 7 months ago by Tim Graham

Patch needs improvement: set

I left comments for improvement on the PR. Please uncheck "Patch needs improvement" after updating.

comment:6 Changed 5 months ago by Rebecca Smith

Cc: Rebecca Smith added
Patch needs improvement: unset
Note: See TracTickets for help on using tickets.
Back to Top