3.xadmin配置
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='用户操作'
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· DeepSeek火爆全网,官网宕机?本地部署一个随便玩「LLM探索」
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 上周热点回顾(1.20-1.26)
· 【译】.NET 升级助手现在支持升级到集中式包管理
2019-06-09 广告小程序后端开发(16.优惠券系统:原理流程图,奖品实验数据,生成二维码)
2018-06-09 python datetime 字符串 时间戳