注:本篇文章不适合小白看,适合有一定django基础的
1.首先在Pycharm终端pip install xadmin,会自动将xadmin的依赖包和符合xadmin版本的django安装
2.然后去github下搜索下载xadmin的源码包,将xadmin包放到extra_apps下,终端运行pip uninstall xadmin卸载之前下载的xadmin包
注:要将extra_apps配置到settings.py中
sys.path.insert(0,os.path.join(BASE_DIR, “extra_apps”))
3.将xadmin和crispy_forms注册到settings下
1.在自己创建的每个app文件下加上adminx.py,然后根据自己的models编写相应的代码
示例代码:
import xadmin
from .models import EmailVerifycord,Banner
from xadmin import views #1,2
class BaseSetting(object):
"""打开xadmin更换主题功能:1"""
enable_themes = True
use_bootswatch = True
class GlobalSettings(object):
"""页头,页脚,表收起显示设置:2"""
site_title = "天下无双帮会管理系统"
site_footer = "天下无双帮会"
menu_style = "accordion"
class EmailVerifycordAdmin(object):
#显示列
list_display = ['code','email','send_type','send_time']
#搜索
search_fields = ['code','email','send_type']
#过滤器
list_filter = ['code','email','send_type','send_time']
class BannerAdmin(object):
list_display = ['title','image','url','index','add_time']
search_fields = ['title','image','url','index']
list_filter = ['title','image','url','index','add_time']
#注册
xadmin.site.register(EmailVerifycord, EmailVerifycordAdmin)
xadmin.site.register(Banner,BannerAdmin)
xadmin.site.register(views.BaseAdminView,BaseSetting)#1
xadmin.site.register(views.CommAdminView,GlobalSettings)#2
2.后台表名更改为中文显示
(1).在apps.py文件下加上
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
#更改xadmin表名为中文
verbose_name = u"用户信息"
(2).在__init__.py文件下加上
#加载更改xadmin表名为中文
default_app_config = "users.apps.UsersConfig"