一、如何更改后台标题,页脚
在应用的admin.py 或是adminx.py中添加
from xadmin import views @xadmin.sites.register(views.CommAdminView) class GlobalSetting(object): # 改成折叠菜单 menu_style = 'accordion' # 左上角标题 site_title = 'CMS后台' # 设置主页页脚 site_footer = 'Current Editor (2018)'
二、如何添加切换主题
在应用的admin.py 或是adminx.py中设置
@xadmin.sites.register(views.BaseAdminView) class BaseSetting(object): # 开启主题切换按钮 enable_themes = True use_bootswatch = True
三、自定义form以及chart
## 自定义编辑Form界面 form_layout = ( Main( TabHolder( Tab( "基础信息", Fieldset( "基础配置", Row( "name", "idc" ), Row( "internal_ip", "service_type" ), Row( "active", ), ), ), ), ), Side( Fieldset( "帐号信息", "ssh_port", "ip", 'user', 'password', "status", ), ) ) ## 绘图 data_charts = { "host_service_type_counts": { 'title' : '主机类型统计', 'x-field' : "service_type", 'y-field' : ("service_type"), 'option' : { "series" : {"bars":{"align":"center", "barWidth": 0.8,"show":True}}, "xaxis" : {"aggregate":"count","mode":"categories"} }, }, "host_idc_counts" : { 'title' : '机房统计', 'x-field' : "idc", 'y-field' : ("idc",), 'option' : { "series" : {"bars":{"align":"center", "barWidth": 0.5,"show":True}}, "xaxis" : {"aggregate":"count","mode":"categories"} } } }
四、其它一些神神叨叨的配置
@xadmin.sites.register( IDC ) class IdcAdmin( object ): # list显示字段 list_display = ("name", "description", "contact", "telphone", "address", "customer_id", "expire", "create_time") # list中哪个字段带链接,点击可以进入编辑 list_display_links = ("name",) # 搜索框 search_fields = ("name") # 过滤器搜索字段 list_filter = ("address", "customer_id") # 显示还原按钮,删除修改的信息可以还原 reversion_enable = True # 列聚合,可用的值:"count","min","max","avg", "sum" aggregate_fields = {"expire": "max"} # # grid_layouts = ("table", "thumbnails") # list页面直接编辑 list_editable = ( "name", "description", "contact", "telphone", "address", "customer_id", "expire" ) # 自动刷新 refresh_times = (3, 5, 10) # 添加数据时候,一步一步提供数据 wizard_form_list = [ ("基础信息", ("name", "contact", "telphone", "address")), ("其它信息", ("customer_id", "expire", "description")), ]