标签:ati pack 菜单 字段 tps pps tool mes img
https://github.com/sshwsfc/xadmin/archive/master.zip
解压缩, 得到xadmin文件夹, 复制到项目的extra_apps
在Django中的根目录下创建python package, 命名为extra_apps (如果不存在此文件夹则创建, 然后鼠标右键, extra_apps
, Mark Directory as
-Sources Root
)
创建完extra_apps
, 需要在settings
里配置下extra_apps
, 设置为可搜索的路径
import sys
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(BASE_DIR, 'xadmin'))
把xadmin
文件夹复制到 extra_apps
pip3 install django-import-export -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install django-reversion -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install django-formtools==2.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install future -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install httplib2 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install six -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install django-crispy-forms -i https://pypi.tuna.tsinghua.edu.cn/simple
LANGUAGE_CODE = 'zh-hans' # 修改为中文
TIME_ZONE = 'Asia/Shanghai' # 修改时区为东八区的时间
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api.apps.ApiConfig',
'rest_framework.apps.RestFrameworkConfig',
'repo.apps.RepoConfig',
'web.apps.WebConfig',
'xadmin.apps.XAdminConfig',
'crispy_forms',
]
urls.py
的adminimport xadmin
urlpatterns = [
# url(r'^admin/', admin.site.urls),
url(r'^xadmin/', xadmin.site.urls),
url(r'^web/', include('web.urls', namespace='web')),
url(r'^asset/', views.Asset.as_view()),
]
python3 manager.py makemigrations
python3 manager.py migrate
迁移完成后, 看到多出来了几张表
adminx.py
文件import xadmin
from repo import models
from xadmin import views
class UserProfileAdmin(object):
#### 显示字段名称
list_display = ['id', 'name', 'email', 'phone', 'mobile']
#### 搜索时可输入的字段内容
search_fields = ['id', 'name', 'email', 'phone']
#### 可编辑的列名
list_editable = ['name', 'email', 'phone', 'mobile']
#### 每页显示多少条
list_per_page = 20
# 根据id排序
ordering = ('id', )
# 设置只读字段
readonly_fields = ('email', )
# 显示详情
show_detail_fields = ['name', 'phone', 'email']
class ServerAdmin(object):
list_display = ['hostname', 'os_platform', 'manufacturer', 'sn', 'cpu_count', 'cpu_model']
show_detail_fields = ['hostname']
xadmin.site.register(models.UserProfile, UserProfileAdmin)
xadmin.site.register(models.Server, ServerAdmin)
class GlobalSettings(object):
# 修改title
site_title = 'cmdb管理后台'
# 修改footer
site_foot = 'xxx公司'
# 收起菜单
menu_style = 'accordion'
# 设置models图标
global_search_models = [models.UserProfile, models.Server]
global_models_icon = {
models.Server: 'fa fa-linux',
models.UserProfile: 'fa fa-cloud',
}
class BaseSettings(object):
# 开启主题功能
enable_themes = True
use_bootswatch = True
xadmin.site.register(views.CommAdminView, GlobalSettings)
xadmin.site.register(views.BaseAdminView, BaseSettings)
标签:ati pack 菜单 字段 tps pps tool mes img
原文地址:https://www.cnblogs.com/cjwnb/p/11919238.html