Django-JET主题使用

自定义Dashboard

  1. 创建一个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
    ))
  2. 然后在settings.py中添加

    1
    JET_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'
  3. 这时我们就完成了第一个小widget,LinkList, 现在页面看起来是这样的

    img

Dashboard模块

class jet.dashboard.modules.LinkList(title=None, children=[], **kwargs)

img

栗子:

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’

布局方式,有两种值:stackedinline

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
))