xadmin注册模型类添加测试数据
安装xadmin
1、在users中新建adminx.py
根据models中的表,注册、导入xadmin
path: apps/users/adminx.py
import xadmin
from .models import BannerInfo,EmailVerifyCode
from xadmin import views
#配置xadmin主题,注册的时候要用到专用的view去注册
class BaseXadminSetting(object):
enable_themes = True
use_bootswatch = True
class CommXadminSetting(object):
site_title = '谷粒教育后台管理系统'
site_footer = '尚硅谷it教育'
menu_style = 'accordion'
class BannerInfoXadmin(object):
list_display = ['image','url','add_time']
search_fields = ['image', 'url']
list_filter = ['image', 'url']
class EmailVerifyCodeXadmin(object):
list_display = ['code', 'email', 'send_type','add_time']
xadmin.site.register(BannerInfo,BannerInfoXadmin)
xadmin.site.register(EmailVerifyCode,EmailVerifyCodeXadmin)
#注册主题类
xadmin.site.register(views.BaseAdminView,BaseXadminSetting)
#注册全局样式的类
xadmin.site.register(views.CommAdminView,CommXadminSetting)
效果
其他app同理,
2、添加测试数据
3、修改xadmin中的apps名
4、Xadmin基础设置和icon设置
apps/users/adminx.py
import xadmin
from .models import BannerInfo,EmailVerifyCode
from xadmin import views
#配置xadmin主题,注册的时候要用到专用的view去注册
class BaseXadminSetting(object):
enable_themes = True
use_bootswatch = True
class CommXadminSetting(object):
site_title = '谷粒教育后台管理系统'
site_footer = '尚硅谷it教育'
# 下拉菜单
menu_style = 'accordion'
class BannerInfoXadmin(object):
list_display = ['image','url','add_time']
search_fields = ['image', 'url']
list_filter = ['image', 'url']
class EmailVerifyCodeXadmin(object):
list_display = ['code', 'email', 'send_type','add_time']
xadmin.site.register(BannerInfo,BannerInfoXadmin)
xadmin.site.register(EmailVerifyCode,EmailVerifyCodeXadmin)
#注册主题类
xadmin.site.register(views.BaseAdminView,BaseXadminSetting)
#注册全局样式的类
xadmin.site.register(views.CommAdminView,CommXadminSetting)
修改图标(字体图标)
在font awesome中下载最新版:
https://fontawesome.dashgame.com/
粘贴覆盖到:extra_apps/xadmin/static/xadmin/vendor/font-awesome
选择需要的图标:
可能会遇到一些问题,看课程