Opened 16 years ago
Last modified 12 years ago
#10057 closed
ModelAdmin.render_change_form should not override the 'has_delete' option — at Initial Version
Reported by: | rajeesh | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | ModelAdmin render_change_form |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | yes |
Description
The methods, add_view and change_view in class ModelAdmin in options.py, call another method, render_change_form, to display the add and edit forms respectively. The add_view passes it a context dictionary which includes a 'has_delete' option which in turn makes the 'Delete' button invisible from the add form. When I wanted to make the Delete button invisible from the edit form also (based on specific conditions), I hoped a similar approach in change_view, that is, including 'has_delete' option may help the cause. But render_change_form seems to ignore that option explained below:
{{
def render_change_form(self, request, context, add=False, change=False, form_url=, obj=None):
#few lines here
context.update({
#few_other_options_here
################################################################
'has_delete_permission': self.has_delete_permission(request, obj)
################################################################
# The above line is what overrides the has_delete option passed!
#more code here
}}
Changing the above mentioned line to
{{ 'has_delete_permission': context.get('show_delete',True) and \
self.has_delete_permission(request, obj)
}}
may solve the problem. By this way, the developer can decide when to make the Delete button visible just by passing an extra context option, 'has_delete' to the change_view.
Looking forward to alternative suggestions and comments