Opened 6 years ago

Closed 2 years ago

Last modified 2 years ago

#11772 closed New feature (wontfix)

ModelAdmin - added a model_modified hook for full CRUD support

Reported by: Rupe 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 Rupe 6 years ago.
modelAdmin_model_modified_hook.2.diff (2.2 KB) - added by Rupe 6 years ago.
Added hook to the changelist_view() bulk update

Download all attachments as: .zip

Change History (14)

Changed 6 years ago by Rupe

comment:1 Changed 6 years ago by Mnewman

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

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

Changed 6 years ago by Rupe

Added hook to the changelist_view() bulk update

comment:3 Changed 6 years ago by Rupe

  • milestone set to 1.2

comment:4 Changed 5 years ago by tobias

  • Needs documentation set
  • Needs tests set
  • Triage Stage changed from Unreviewed to Design decision needed

comment:5 Changed 5 years ago by ubernostrum

  • milestone 1.2 deleted

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

comment:6 Changed 5 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 5 years ago by Rupe

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

comment:8 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:9 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:10 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:11 Changed 2 years ago by aaugustin

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

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 2 years ago by mitar

What about my proposal about signals?

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