From 5609ec4a9c4e2436b107f42582ae20c2397f85ea Mon Sep 17 00:00:00 2001 From: James Socol Date: Fri, 4 Mar 2011 09:38:14 -0500 Subject: [PATCH] Help for templates. --- adminplus/templates/adminplus/base.html | 7 ++++ docs/custom-admin-views.rst | 44 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 adminplus/templates/adminplus/base.html create mode 100644 docs/custom-admin-views.rst diff --git a/adminplus/templates/adminplus/base.html b/adminplus/templates/adminplus/base.html new file mode 100644 index 0000000..a9bc658 --- /dev/null +++ b/adminplus/templates/adminplus/base.html @@ -0,0 +1,7 @@ +{% extends "admin/base_site.html" %} + +{% block breadcrumbs %} + +{% endblock %} diff --git a/docs/custom-admin-views.rst b/docs/custom-admin-views.rst new file mode 100644 index 0000000..3a6220f --- /dev/null +++ b/docs/custom-admin-views.rst @@ -0,0 +1,44 @@ +=========================== +Creating Custom Admin Views +=========================== + +Any view can be used as a custom admin view in AdminPlus. All the normal rules +apply: accept a request and possibly other parameters, return a response, and +you're good. + +Making views look like the rest of the admin is pretty straight-forward, too. + + +Extending the Admin Templates +============================= + +AdminPlus contains an base template you can easily extend. It includes the +breadcrumb boilerplate. You can also extend ``admin/base_site.html`` directly. + +Your view should pass a ``title`` value to the template to make things pretty. + +Here's an example template:: + + {# myapp/admin/myview.html #} + {% extends 'adminplus/base.html' %} + + {% block content %} + {# Do what you gotta do. #} + {% endblock %} + +That's pretty much it! Now here's how you use it:: + + # myapp/admin.py + # Using AdminPlus + from django.contrib import admin + from django.shortcuts import render_to_response + from django.template import RequestContext + + def myview(request): + # Fanciness. + return render_to_response('myapp/admin/myview.html', + {'title': 'My View'}, + RequestContext(request, {})) + admin.site.register_view('mypath', myview, 'My View') + +Voila! Instant custom admin page that looks great.