Changes between Initial Version and Version 1 of Ticket #10057
- Timestamp:
- Jan 17, 2009, 2:22:29 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #10057 – Description
initial v1 1 1 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: 2 2 3 {{ 3 {{{ 4 4 def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): 5 5 #few lines here … … 11 11 # The above line is what overrides the has_delete option passed! 12 12 #more code here 13 }} 13 }}} 14 14 15 15 Changing the above mentioned line to 16 16 17 {{ 'has_delete_permission': context.get('show_delete',True) and \ 17 {{{ 18 'has_delete_permission': context.get('show_delete',True) and \ 18 19 self.has_delete_permission(request, obj) 19 }} 20 }}} 20 21 21 22 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.