Environment Introduction
- python3 +django2.1.8
- windows environment
Build management system has never been easier
You simply use X-admin-defined data fields and other information you can instantly get a full-featured management systems. Not only that, you can easily expand more customization and system interface.
Three characteristics
Based Bootstrap3
Xadmin use Bootstrap3.0 carefully crafted framework. Based Bootstrap3, Xadmin inherently supports seamless viewing on multiple screens, and fully supports Bootstrap theme templates to make your management background is also dynamic and diverse up.
Built-in feature-rich
Xadmin as a comprehensive back-office management system framework, not only provides the basic CRUD functions, but also built a wealth of plug-in function. Including data export, bookmarks, charts, data and picture albums Add Wizard and other extensions.
Really powerful plugin system
Xadmin plug-in system design draws on the success of other areas of the frame, so that plug-ins can extend any function of a point system. For developers, the plug-in development Xadmin simple; for users, facilitate Xadmin the plug-in installed.
X-admin download
- Enter git website: https://github.com/sshwsfc/xadmin
- Select django2 to download, not to download the main branch
Switch to the virtual environment for installation
Installation command: pip install local path + filename
After the successful installation xadmin and crispy_forms added to the application package
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'xadmin', 'crispy_forms', ]
Admin configuration changes in the main directory urls
- The xadmin migration-table
- Create a super administrator account and login account generate background
- After the source code for the convenience of xadmin modify operation, it can be directly downloaded xadmin-master.zip package to decompress it, find xadmin files unzipped file copied to extra_apps package under the project root directory (you need to create extra_apps package) this operation is a source installation
FIG operation is completed:
Test whether the source installation xadmin successful, can enter xadmin management background, import xadmin module package at the root level urls extra_apps
from django.urls import path,include from extra_apps import xadmin urlpatterns = [ path('xadmin/', xadmin.site.urls), ] #可以进入表示成功
app to modify settings in the configuration file is registered in xadmin extra_apps.xadmin
Refresh the page, xadmin admin page displaying unchanged, indicating a successful installation source
Use xadmin Register Register Register model table while the theme and modify text
Registration Example:
#某app下的某models类如下
class LessonInfo(models.Model):
name = models.CharField(max_length=50, verbose_name='章节名称')
courseinfo = models.ForeignKey(CourseInfo,verbose_name='所属课程',on_delete=models.CASCADE)
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')
def __str__(self):
return self.name
class Meta:
verbose_name = '章节信息'
verbose_name_plural = verbose_name
#在app下的models同级创建adminx.py文件
import xadmin
from .models import *
from xadmin import views
class LessonInfoXadmin(object):
#ist_display添加后台可显示字段
#search_fields、list_filter添加搜索框和过滤器
list_display = ['name', 'courseinfo', 'add_time']
search_fields = ['name']
list_filter = ['name']
class BaseXadminSetting(object):
'''配置xadmin主题,注册的时候要用到专用的view去注册'''
enable_themes = True
use_bootswatch = True
class CommXadminSetting(object):
'''#注册全局样式的类'''
site_title = '即速教育后台管理系统'
site_footer = '即速教育'
menu_style = 'accordion'
xadmin.site.register(LessonInfo,LessonInfoXadmin)
#注册主题类
xadmin.site.register(views.BaseAdminView,BaseXadminSetting)
#注册全局样式的类
xadmin.site.register(views.CommAdminView,CommXadminSetting)
#备注:
1.多个app需要注册的时候 可以将app放置在apps文件夹中,并且在settings.py中注册app时格式如下
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users.apps.UsersConfig',
'courses.apps.CoursesConfig',
'orgs.apps.OrgsConfig',
'operations.apps.OperationsConfig',
'extra_apps.xadmin',
'crispy_forms',
]
2.将apps文件夹标记为根文件夹
apps-->MARK Directory as -->Resouce ROOT
3.将每个app下的apps.py文件中的name修改为app名
例子如下:
class CoursesConfig(AppConfig):
#name = 'apps/courses' 修改
name = 'courses'
verbose_name = '课程模块'
4.修改文字和时区
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
Background icon to modify the source code of xadmin
Download icon library website: http://www.fontawesome.com.cn/
Unzip the download fonts, css folder files under the cover of the same name "extra_apps / xadmin / static / xadmin / vendor / font-awesome" folder
Add the following fields in the class adminx
class LessonInfoXadmin(object): list_display = ['name','add_time'] model_icon = 'fa fa-bath'