from django.template import loader, RequestContext from django.http import Http404, HttpResponse, HttpResponseForbidden from django.core.xheaders import populate_xheaders from django.core.paginator import Paginator, InvalidPage from django.core.exceptions import ObjectDoesNotExist from django.db.models.loading import get_model def print_detail(request, app_label, model_name, pk, template_name=None, template_name_field=None, template_loader=loader, extra_context=None, context_processors=None, template_object_name='object', mimetype=None): """ Put the following line in your urls.py BEFORE your admin include (r'^admin/(?P[\d\w]+)/(?P[\d\w]+)/(?P[\d]+)/print/', 'biola.utils.print_view.print_detail'), Generic detail of an object. Templates: ``/_print_detail.html`` Context: object the object """ if not request.user.is_staff: return HttpResponseForbidden() if extra_context is None: extra_context = {} try: model = get_model(app_label, model_name) obj = model.objects.get(pk=pk) except ObjectDoesNotExist: raise Http404, "No %s found matching the query" % (model._meta.verbose_name) if not template_name: template_name = "%s/%s_print_detail.html" % (model._meta.app_label, model._meta.object_name.lower()) if template_name_field: template_name_list = [getattr(obj, template_name_field), template_name] t = template_loader.select_template(template_name_list) else: t = template_loader.get_template(template_name) c = RequestContext(request, { template_object_name: obj, }, context_processors) for key, value in extra_context.items(): if callable(value): c[key] = value() else: c[key] = value response = HttpResponse(t.render(c), mimetype=mimetype) populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name)) return response """ Create your own change_form.html for your admin view: {% extends "admin/change_form.html" %} {% load i18n %} {% block object-tools %} {% if change %}{% if not is_popup %} {% endif %}{% endif %} {% endblock %} """