1、安装xadmin
参见我的另一篇文章
2、 在installed_app中注册
'xadmin',
'crispy_forms',
'reversion',
3、配置urls(创建项目时的总的urls)
from django.contrib import admin
from django.urls import path, re_path, include
import xadmin
xadmin.autodiscover()
from xadmin.plugins import xversion
xversion.register_models()
path('xadmin/', xadmin.site.urls),
4、在子应用中配置“adminx.py”文件
from xadmin import views
from .models import Banner, Nav
import xadmin
class BaseSetting(object):
enable_themes = True # 开启主题切换
use_bootswatch = True
xadmin.site.register(views.BaseAdminView, BaseSetting)
class GlobalSettings(object):
"""xadmin的全局配置"""
site_title = "sitename"
site_footer = "x科技有限责任公司技术支持"
menu_style = "accordion" # 设置菜单折叠
xadmin.site.register(views.CommAdminView, GlobalSettings)
class BannerModelAdmin(object):
list_display = ['name', 'orders', 'is_show']
xadmin.site.register(Banner, BannerModelAdmin) # 注册模型
网友评论