views:

2137

answers:

3

I'm looking to add an extra set of pages to my auto-generated admin site. I want to generate reports off my models and some logs surrounding it. The actual generating isn't the issue.

How do I:

  1. Make the report output look like it's an admin page, with breadcrumbs, similarly formatted table, etc?
  2. Register the view so it shows up on the front page?
+2  A: 

In terms of generating the look and feel of admin, it should be trivial to inherit the parent pages of the admin and insert your own template content into the appropriate blocks.

Take a look at the markup (including id and class attributes) in the default admin pages and try to get an understanding of how things are styled consistently. If you are including the admin CSS on the page you should get an awful lot of it for free.

For further information, take a look at the admin docs: http://docs.djangoproject.com/en/dev/ref/contrib/admin/

Andy Hume
+3  A: 

The above answer didn't address question 2, at least directly... the "hack" way to get your custom view to show up as the front page of the admin is probably to just override it in the urlconf:

(r'^admin/$', my.custom.admin.homepage),

before the normal admin line:

(r'^admin/', admin.site.root),

the "right" way to do it, though, is to make your admin a custom instance of AdminSite and override the index_template setting. http://docs.djangoproject.com/en/dev/ref/contrib/admin/#root-and-login-templates

Yoni Samlan
OP didn't ask for custom view to show up AS the front page, rather ON the front page. Which is rather more complex, as it involves copying and modifying the admin index template.
Carl Meyer
+2  A: 

Here's a base template to get you started:

    {% extends "admin/base_site.html" %}
    {% load adminmedia %}

    {% block extrahead %}
    {% endblock %}
    {% block coltype %}flex{% endblock %}
    {% block bodyclass %}change-list{% endblock %}
    {% block stylesheet %}{% admin_media_prefix %}css/changelists.css{% endblock %}
    {% block extrastyle %}
    <link rel="stylesheet" type="text/css" href="{{settings.MEDIA_URL}}/stylesheets/extra_admin.css" />
    {% endblock %}
    {% block breadcrumbs %}<div class="breadcrumbs"><a href="/admin/">Home</a>&nbsp;&rsaquo;&nbsp;{{page_title}}</div>{% endblock %}
    {% block content %}
    <div id="content-main">
        <h1>{{page_title}}</h1>
        {{page_content}}
    </div>
    {% endblock %}
andybak