Opened 16 years ago
Closed 12 years ago
#10057 closed Bug (fixed)
ModelAdmin.render_change_form should not override the 'has_delete' option
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 (last modified by )
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
Attachments (2)
Change History (15)
comment:1 by , 16 years ago
Description: | modified (diff) |
---|
comment:4 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
A better approach would be to just make a custom template for the model in question; see http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates
comment:5 by , 15 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
Just ran into the same problem. The logic that produces a True
or False
for show_delete_link
in django.contrib.admin.templatetags.admin_modify seems a bit flawed because the value of
show_delete in the passed context is essentially always ignored because the
changed boolean is hard-coded to True by the admin system if you are viewing the
change_view` with a bound Form.
I've attached a patch that ensures that show_delete
is checked if it exists, otherwise it always displays the delete link.
by , 15 years ago
Attachment: | show_delete.patch added |
---|
comment:6 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
From a quick look at the logic changes in the attached patch, it looks like a valid issue.
comment:7 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:8 by , 13 years ago
UI/UX: | set |
---|
comment:12 by , 12 years ago
Needs tests: | unset |
---|
Updated patcoll's patch to current trunk and added a test.
by , 12 years ago
Attachment: | 10057.diff added |
---|
comment:13 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(edited description to make it legible, next time please use the Preview button)