使用xadmin覆盖Django的admin
安装xadmin
pip 安装 pip install xadmin 可能会报错
pip install git+git://github.com/sshwsfc/xadmin.git
安装后要使用需要在setting里面注册三个app
INSTALLED_APPS = [ .... #xadmin 'xadmin', 'crispy_forms', 'reversion', ]
修改根目录的urls.py文件
import xadmin xadmin.autodiscover() from xadmin.plugins import xversion xversion.register_models() urlpatterns = [ url(r'^xadmin/', include(xadmin.site.urls)),
然后需要新建一个adminx.py的文件,里面来注册你的模型
# -*- coding: utf-8 -*- # from django.contrib import admin import xadmin from .models import * from xadmin import views # Register your models here. # class GlobalSettings(object): site_title = "Wellhotel后台管理系统" site_footer = "Wellhotel后台管理系统" menu_style = 'accordion'
class basesetting(object):
enable_themes = True
use_bootswatch = True
xadmin.site.register(views.CommAdminView,GlobalSettings)
xadmin.site.register(views.BaseAdminView,basesetting)
xadmin.site.register(subclass_details)
xadmin.site.register(Organization)
xadmin.site.register(DeviceInfo)
# xadmin.site.register(NormalUser)
xadmin.site.register(Price)
GlobalSettings里面的site_title是xadmin左上角的log,site_footer是xadmin下面的那个log。menu_style设置左边的导航栏为点击下拉的那种
basesetting里面是打开后台的主题系统。xadmin是默认关闭的。打开后可以选择不同的主题。
官方文档 https://xadmin.readthedocs.io/en/docs-chinese/quickstart.html#