自定义Dashboard
创建一个dashboard.py
文件,这里是将该文件放到了项目根目录,并写入如下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| from django.utils.translation import ugettext_lazy as _ from jet.dashboard import modules from jet.dashboard.dashboard import Dashboard, AppIndexDashboard class CustomIndexDashboard(Dashboard): columns = 3 def init_with_context(self, context): self.available_children.append(modules.LinkList) self.children.append(modules.LinkList( _('Support'), children=[ { 'title': _('Django documentation'), 'url': 'http://docs.djangoproject.com/', 'external': True, }, { 'title': _('Django "django-users" mailing list'), 'url': 'http://groups.google.com/group/django-users', 'external': True, }, { 'title': _('Django irc channel'), 'url': 'irc://irc.freenode.net/django', 'external': True, }, ], column=0, order=0 ))
|
然后在settings.py
中添加
1
| JET_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'
|
这时我们就完成了第一个小widget
,LinkList
, 现在页面看起来是这样的
Dashboard模块
LinkList
class jet.dashboard.modules.LinkList(title=None, children=[], **kwargs)
栗子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| from django.utils.translation import ugettext_lazy as _ from jet.dashboard import modules from jet.dashboard.dashboard import Dashboard, AppIndexDashboard class CustomIndexDashboard(Dashboard): columns = 3 def init_with_context(self, context): self.available_children.append(modules.LinkList) self.children.append(modules.LinkList( _('Support'), children=[ { 'title': _('Django documentation'), 'url': 'http://docs.djangoproject.com/', 'external': True, }, { 'title': _('Django "django-users" mailing list'), 'url': 'http://groups.google.com/group/django-users', 'external': True, }, { 'title': _('Django irc channel'), 'url': 'irc://irc.freenode.net/django', 'external': True, }, ], column=0, order=0 ))
|
参数有以下几种
children = []
每一个链接都是一个字典类型,比如:
1 2 3 4 5 6 7 8
| [ { 'title': _('Django documentation'), 'url': 'http://docs.djangoproject.com/', 'external': True, }, ... ]
|
layout = ‘stacked’
布局方式,有两种值:stacked
、inline
AppList
显示每个App
及应用下Model
的链接,
exclude
指定不显示的Model,格式为App.model
的元组,可以用代替全部的model,比如`业绩.`
models
指定显示的Model,格式为App.model
的元组,可以用代替全部的model,比如`业绩.`
栗子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| from django.utils.translation import ugettext_lazy as _ from jet.dashboard import modules from jet.dashboard.dashboard import Dashboard, AppIndexDashboard class CustomIndexDashboard(Dashboard): columns = 3 def init_with_context(self, context): self.children.append(modules.AppList( _('应用'), exclude=('auth.*', '业绩.个人明细表'), models=('业绩.*',), column=1, order=0 ))
|
ModelList
同 AppList
历史记录
展示管理员 最近的操作记录
exclude_list
不显示哪些Model的记录, 格式为App.model
的元组,可以用代替全部的model,比如`业绩.`
include_list
显示哪些Model的记录, 格式为App.model
的元组,可以用代替全部的model,比如`业绩.`
limit
显示的条数
栗子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| from django.utils.translation import ugettext_lazy as _ from jet.dashboard import modules from jet.dashboard.dashboard import Dashboard, AppIndexDashboard class CustomIndexDashboard(Dashboard): columns = 3 def init_with_context(self, context): self.children.append(modules.RecentActions( _('操作日志'), 10, exclude_list=('auth.*',), include_list=('考核.*',), column=2, order=0 ))
|