xadmin配置
1.在每个apps下新建adminx.py
1.在apps/users下新建adminx.py:
import xadmin from xadmin import views from .models import UserProfile,PianQu,LouMing,DanYuan,ZhuHu,UserToZhuHu class BaseSetting(object): enable_themes = True use_bootswatch = True class GlobalSettings(object): site_title = "新中街社区网格化治理信息平台" site_footer = "赤峰市落忆网络科技有限公司" menu_style = "accordion" class UserProfileAdmin(object): list_display = ["username","name","minzu","sex","mobile","address","danwei","is_dangyuan","hujixz","huji","wenhua", "hunyin","no","chusheng","is_teshu","teshu","beizhu","power"] list_filter = ["username","name","minzu","sex","mobile","address","danwei","is_dangyuan","hujixz","huji","wenhua", "hunyin","no","chusheng","is_teshu","teshu","beizhu","power"] search_fields = ["username","name","minzu","sex","mobile","address","danwei","is_dangyuan","hujixz","huji","wenhua", "hunyin","no","is_teshu","teshu","beizhu","power"] class PianQuAdmin(object): list_display = ["image_url","name","wgz","add_time"] list_filter = ["name","wgz","add_time"] search_fields = ["name"] class LouMingAdmin(object): list_display = ["name","pianqu","wgy","lz","add_time"] list_filter = ["name","pianqu","wgy","add_time"] search_fields = ["name"] class DanYuanAdmin(object): list_display = ["name","lou","dyz","add_time"] list_filter = ["name","lou","dyz","add_time"] search_fields = ["name"] class ZhuHuAdmin(object): list_display = ["name", "dy", "hz", "add_time"] list_filter = ["name", "dy", "hz", "add_time"] search_fields = ["name"] class UserToZhuHuAdmin(object): list_display = ["user", "zhhu", "add_time"] list_filter = ["user", "zhhu", "add_time"] # 先注销模块,再注册 xadmin.site.unregister(UserProfile) xadmin.site.register(UserProfile, UserProfileAdmin) xadmin.site.register(views.BaseAdminView, BaseSetting) xadmin.site.register(views.CommAdminView, GlobalSettings) xadmin.site.register(PianQu, PianQuAdmin) xadmin.site.register(LouMing, LouMingAdmin) xadmin.site.register(DanYuan, DanYuanAdmin) xadmin.site.register(ZhuHu, ZhuHuAdmin) xadmin.site.register(UserToZhuHu, UserToZhuHuAdmin)
2.在apps/goods下新建adminx.py:
备用
3.在apps/trade下新建adminx.py:
备用
4.在apps/user_operations下新建adminx.py:
import xadmin from .models import Notice class NoticeAdmin(object): list_display = ["user","content","add_time"] list_filter = ["user","content","add_time"] search_fields=["content"] xadmin.site.register(Notice,NoticeAdmin)
2.xadmin安装(前面已完成)
3.下载安装xadmin所需的依赖库(以前都安装过了):
1.安装依赖包 django-crispy-forms django-reversion django-formtools future httplib2 six django-import-export
pip --default-timeout=100 install django-crispy-forms pip --default-timeout=100 install django-reversion pip --default-timeout=100 install django-formtools pip --default-timeout=100 install future pip --default-timeout=100 install httplib2 pip --default-timeout=100 install six pip --default-timeout=100 install django-import-export
2.安装用来操作和导出Excel文件的包 xlwt xlsxwriter
pip --default-timeout=100 install xlwt
pip --default-timeout=100 install xlsxwriter
4.在settings.py中注册xadmin和crispy_forms(前面已完成)
5.执行数据更新命令
python manage.py makemigrations
python manage.py migrate
6.创建超级用户root
python manage.py createsuperuser Username: root 邮箱: 1@1.com Password: Password (again):
7 .将语言设定为中文
1.在settings.py中:
LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False
2.在每个app下的apps.py中做修改,加上verbose_name
1.在apps/users/apps.py中:
from django.apps import AppConfig class UsersConfig(AppConfig): name = 'users' verbose_name='用户'
2.在apps/goods/apps.py中:
from django.apps import AppConfig class GoodsConfig(AppConfig): name = 'goods' verbose_name='商品服务'
3.在apps/trade/apps.py中:
from django.apps import AppConfig class TradeConfig(AppConfig): name = 'trade' verbose_name='交易'
4.在apps/user_operations/apps.py中:
from django.apps import AppConfig class UserOperationsConfig(AppConfig): name = 'user_operations' verbose_name='用户操作'