Code

Opened 2 years ago

Last modified 23 months ago

#17962 new New feature

Django Admin delete_view could benefit from extension points

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

Description

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 gcc 2 years ago.
Patch to add get_deleted_objects() hook to ModelAdmin

Download all attachments as: .zip

Change History (2)

Changed 2 years ago by gcc

Patch to add get_deleted_objects() hook to ModelAdmin

comment:1 Changed 23 months ago by lukeplant

  • Component changed from Uncategorized to contrib.admin
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to New 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.