Better saving in newforms-admin ModelAdmin
|Reported by:||Petr Marhoun <petr.marhoun@…>||Owned by:||jacob|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
There are two very long methods in django.contrib.admin.options.ModelAdmin - save_add and save_change. They do three different things - they save objects, they log what happened and they redirect. So I propose to divide them.
Method add_view would call save_add for saving, log_add for logging and redirect_after_save for redirection. Method change_view would call save_change for saving, log_change for logging and redirect_after_save for redirection.
Methods save_add and save_change would be useful for complex saving which depends on forms and inline formsets together. (It solves #4507.)
Methods log_add and log_change could be used for example for something as AuditModelAdmin or NoLogAdmin.
Method redirect_after_save would be something as render_change_form - technical code common for adding and changing, which is not interesting very much.
I feel that now redirection is quite broken, it does not check permissions correctly. My patch fixes it too.
Change History (17)
comment:1 Changed 7 years ago by brosner
- Keywords nfa-blocker added
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
Changed 7 years ago by shnur
comment:4 Changed 7 years ago by shnur
- Owner changed from nobody to shnur
- Status changed from new to assigned
comment:5 Changed 7 years ago by brosner
- Keywords nfa-blocker removed
- milestone changed from 1.0 alpha to 1.0 beta
comment:7 Changed 7 years ago by jacob
- Owner changed from shnur to jacob
- Patch needs improvement set
- Status changed from assigned to new
- Version changed from newforms-admin to SVN
comment:11 Changed 7 years ago by jacob
- Resolution set to fixed
- Status changed from assigned to closed