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 import ugettext 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