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:
我如何:
- Make the report output look like it's an admin page, with breadcrumbs, similarly formatted table, etc?
- 使报表输出看起来像是一个管理页面,带有面包屑,类似格式的表格等?
- Register the view so it shows up on the front page?
- 注册视图,使其显示在首页?
3 个解决方案
#1
6
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:
上面的回答没有解决问题2,至少是直接的...“hack”方式让你的自定义视图显示为管理员的首页可能只是在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
但是,“正确”的方法是让管理员成为AdminSite的自定义实例并覆盖index_template设置。 http://docs.djangoproject.com/en/dev/ref/contrib/admin/#root-and-login-templates
#2
4
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.
查看默认管理页面中的标记(包括id和类属性),并尝试了解事物的样式是如何一致的。如果你在页面上包含管理员CSS,你应该免费获得大量的。
For further information, take a look at the admin docs: http://docs.djangoproject.com/en/dev/ref/contrib/admin/
有关详细信息,请查看管理员文档:http://docs.djangoproject.com/en/dev/ref/contrib/admin/
#3
2
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> › {{page_title}}</div>{% endblock %}
{% block content %}
<div id="content-main">
<h1>{{page_title}}</h1>
{{page_content}}
</div>
{% endblock %}
#1
6
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:
上面的回答没有解决问题2,至少是直接的...“hack”方式让你的自定义视图显示为管理员的首页可能只是在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
但是,“正确”的方法是让管理员成为AdminSite的自定义实例并覆盖index_template设置。 http://docs.djangoproject.com/en/dev/ref/contrib/admin/#root-and-login-templates
#2
4
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.
查看默认管理页面中的标记(包括id和类属性),并尝试了解事物的样式是如何一致的。如果你在页面上包含管理员CSS,你应该免费获得大量的。
For further information, take a look at the admin docs: http://docs.djangoproject.com/en/dev/ref/contrib/admin/
有关详细信息,请查看管理员文档:http://docs.djangoproject.com/en/dev/ref/contrib/admin/
#3
2
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> › {{page_title}}</div>{% endblock %}
{% block content %}
<div id="content-main">
<h1>{{page_title}}</h1>
{{page_content}}
</div>
{% endblock %}