Opened 14 years ago
Closed 7 years ago
#15522 closed New feature (fixed)
Allow customizing queryset deletion in the delete_selected admin action view
Reported by: | Divad | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | delete_model |
Cc: | Sergiy Kuzmenko, omerd1, commonzenpython@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Based on [Ticket #11108]
The correction 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.
Change History (18)
comment:1 by , 14 years ago
Component: | Uncategorized → django.contrib.admin |
---|
comment:2 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 14 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
I have defined historic models with three states Current / Changed / Deleted, t\
agged with user and timestamp of operation.
so i have defined "delete_model" as:
def delete_model(self, request, obj): obj.user = request.user super(HistoricModelAdmin,self).delete_model(request, obj)
this allows to track the user who deletes an object.
On the other end when bulk delete is triggered with delete action, I do not kno\
w the user who triggered the action, resulting in two different results.
I suppose there could be other users unaware of this two different results to t\
he same action.
But someone could argue that I should define my own delete action instead of us\
ing the default one.
comment:4 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Thanks for the details. I can see the use of knowing which user has performed the bulk delete. However delete_model(self, request, obj)
cannot be used since that method is for one specific object.
As you mentioned, an easy workaround would be to define your own delete action, which you could then wrap around the built-in one.
I agree that it would be nice to have an easier way of achieving that in core, so I'm marking as Accepted.
comment:5 by , 14 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
comment:6 by , 14 years ago
The def delete_model(self, request, obj)
is attached with a class inherited from admin.ModelAdmin
.
So my original idea of changing bulk delete with queryset.delete()
to a modeladmin.delete_model(request,obj)
for each object.
I realize that this can be inefficient but is the only way to ensure consistent behavior for both ways of deleting in admin.
comment:7 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:10 by , 13 years ago
Cc: | added |
---|
comment:11 by , 13 years ago
Cc: | added |
---|
I've encountered this 'feature' while debugging my delete_model.
Another working workaround is to register for pre_delete signal
comment:12 by , 12 years ago
Status: | reopened → new |
---|
comment:13 by , 8 years ago
While I agree that we should keep consistency, in this case I think both actions should be treated separately.
One deletes a single object, the other deletes multiple objects.
Hooking a pre delete signal or calling delete_model have big impact on performance depending on how many objects
are being deleted.
I'd like to propose a change in the delete action that allows for hooking into it before the deletion takes place,
maybe a method in the ModelAdmin
class?
comment:14 by , 8 years ago
Cc: | added |
---|
comment:15 by , 8 years ago
Summary: | delete_model on admin delete action → Allow customizing queryset deletion in the delete_selected admin action view |
---|
#27326 is a duplicate with a patch (but without tests and docs).
comment:16 by , 7 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
The following pull request is based on ticket #27326. ModelAdmin exports a delete_queryset(self, request, queryset) method which can be overriden allowing extra actions during the queryset deletion process.
https://github.com/django/django/pull/8990
comment:17 by , 7 years ago
Patch needs improvement: | unset |
---|
I don't think this is relevant as the delete action performs a bulk delete on the queryset instead of calling
delete()
for each object.If you think I'm mistaken, please reopen but also provide more detailed information (e.g. description of a use case or code samples) about what you're trying to achieve.