Opened 7 years ago

Closed 4 years ago

Last modified 3 years ago

#11772 closed New feature (wontfix)

ModelAdmin - added a model_modified hook for full CRUD support

Reported by: Joshua Russo Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords: modeladmin hook modified save add change delete
Cc: mmitar@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I added a simple hook called model_modified that is called after each insert, update, and delete via the ModelAdmin class. There are times when it's useful to know when a model changes in any way by the user (via the admin app), including delete. The current methodology of overriding the save_model hook does not include delete. The usefulness of this hook over using the model signals for model changes is that you have access to the response object. I used this hook to clear certain session variables that were dependent on the correlating models.

Attachments (2)

modelAdmin_model_modified_hook.diff (1.8 KB) - added by Joshua Russo 7 years ago.
modelAdmin_model_modified_hook.2.diff (2.2 KB) - added by Joshua Russo 7 years ago.
Added hook to the changelist_view() bulk update

Download all attachments as: .zip

Change History (14)

Changed 7 years ago by Joshua Russo

comment:1 Changed 7 years ago by Michael Newman

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Can you clear up for me why you need a hook here? You have access to model.form.has_changed() in any other hook on the modeladmin, and this looks like overkill for me. Maybe I am missing something.

comment:2 Changed 7 years ago by Joshua Russo

The has_changed hook doesn't look like it triggers on the delete of a record.

Changed 7 years ago by Joshua Russo

Added hook to the changelist_view() bulk update

comment:3 Changed 7 years ago by Joshua Russo

milestone: 1.2

comment:4 Changed 7 years ago by Tobias McNulty

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedDesign decision needed

comment:5 Changed 7 years ago by James Bennett

milestone: 1.2

1.2 is feature-frozen, moving this feature request off the milestone.

comment:6 Changed 6 years ago by Mitar

Cc: mmitar@… added

I think we should go for signals here. There is no need to have some new hooks. If there is a wish for changing the response it can always be passed as an argument. Or a sender can be an admin object itself.

In this way it is not necessary to subclass the admin class.

comment:7 Changed 6 years ago by Joshua Russo

I'm ok with that. I'll do up the changes.

comment:8 Changed 5 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:9 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:10 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:11 Changed 4 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

model_modified duplicates existing functionality for hooking on model changes; I don't like that.

This is really a feature request, please take it to django-developers and try to get consensus on a better way of achieving this goal.

comment:12 Changed 3 years ago by Mitar

What about my proposal about signals?

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