﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12660	"Proposal: adding ""render_display_form"" support to ModelAdmin.change_view (per row granular permission system)"	Massimiliano	nobody	"I found often useful in my programs to endow ModelAdmin with the ability to just display the content of a Model instance.

Let me describe you the scenario:
you have a model with an editor field and a status field.

Editors can only modify the instance if it is still in ""draft"" or ""proposed_for_approval"" statuses, but not once it is published; they should be able to search and display published (a.k.a. editable only by superusers) instances.

I use filter items shown by ModelAdmin.change_list using defining an ad-hoc .queryset method; I define has_add/change/delete_permission and a ""new"" has_display_permission() too. Then when an editor clicks on an item in the change_list for which he has no change permission, instead of automatically raising a Permission Denied exception, I check if it's the case to display the instance. So inside ModelAdmin.change_view I replaced:
{{{ 
if not self.has_change_permission(request, obj):
	raise PermissionDenied
}}} with {{{
if not self.has_change_permission(request, obj):
	if not self.has_display_permission(request, obj):
			raise PermissionDenied
	else:
			display_or_change = 'display'
else:
	display_or_change = 'change'
}}}
The last line of ModelAdmin.change_view changes from {{{ return self.render_change_form(request, context, change=True, obj=obj) }}} to {{{
if display_or_change == 'change':
			return self.render_change_form(request, context, change=True, obj=obj)
		else:
			return self.render_display_form(request, context, obj=obj, behave_as='object_detail') }}}

The ModelAdmin.display_form is basicly a kind of django.views.generic.list_detail.object_detail. The parameter behave_as instructs render_display_form if it has search for a TEMPLATE_DIR/APP/MODEL_detail.html or a more generic self.display_form_template or TEMPLATE_DIR/(%s/%s/)display_form.html the same way ModelAdmin.render_change_form does."		closed	contrib.admin	1.2-alpha		duplicate	row permission view change display		Unreviewed	0	0	0	0	0	0
