Better saving in newforms-admin ModelAdmin
|Reported by:||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:7 Changed 8 years ago by
|Owner:||changed from shnur to Jacob|
|Patch needs improvement:||set|
|Status:||assigned → new|
|Version:||newforms-admin → SVN|