第五章 Xadmin搭建後臺管理系統
阿新 • • 發佈:2019-01-24
1.在github中下載 xadmin原始碼,在工程根目錄下建立extra_apps存放xadmin原始碼
2.建立和extra_apps同級的資料夾apps存放自己的app,然後將users放到下面
3.在OnlineNotes下OnlineNotes中的settings假新增 下面路徑。以至於在工程執行時可以找到xadmin和其他app
import os import sys # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(BASE_DIR, 'extra_apps')) sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
4.在users檔案下建立xadmin.py 新增如下內容
# -*- coding: utf-8 -*- import xadmin from xadmin import views from xadmin.plugins.auth import UserAdmin from xadmin.layout import Fieldset, Main, Side, Row from django.utils.translation importugettext as _ from .models import UserProfile class UserProfileAdmin(UserAdmin): model_icon = 'fa fa-address-book-o' def get_form_layout(self): if self.org_obj: self.form_layout = ( Main( Fieldset('', 'username', 'password', css_class='unsort no_title' ), Fieldset(_('Personal info'), Row('first_name', 'last_name'), 'email' ), Fieldset(_('Permissions'), 'groups', 'user_permissions' ), Fieldset(_('Important dates'), 'last_login', 'date_joined' ), ), Side( Fieldset(_('Status'), 'is_active', 'is_staff', 'is_superuser', ), ) ) return super(UserAdmin, self).get_form_layout() xadmin.site.unregister(UserProfile) xadmin.site.register(UserProfile, UserProfileAdmin)
其他全域性配置
class BaseSetting(object): enable_themes = True use_bootswatch = True class GlobalSettings(object): site_title = "個人線上筆記管理系統" site_footer = "個人線上筆記" menu_style = "accordion" xadmin.site.register(views.BaseAdminView, BaseSetting) xadmin.site.register(views.CommAdminView, GlobalSettings)
替換font圖示 去 http://fontawesome.io/#modal-download 下載
只需替換 OnlineNotes\extra_apps\xadmin\static\xadmin\vendor\font-awesome\ 下的css和fonts