任意app中修改adminx.py,并注册。
修改名称和脚标
1.修改名称 site_title
class GlobalSettings(object):
site_title = '慕学后台管理系统'
2.修改footer site_footer
class GlobalSettings(object):
site_title = '慕学后台管理系统'
site_footer = '慕学在线网'
3.注册生效
xadmin.site.register(xadmin.views.CommAdminView, GlobalSettings)
4.结果
修改主题等基本设置
1.增加修改主题选项
class BaseSettings(object):
enable_themes = True
use_bootswatch = True
2.左侧apps是否默认折叠并显示数量
class GlobalSettings(object):
site_title = '慕学后台管理系统'
site_footer = '慕学在线网'
menu_style = 'accordion'
完整代码
import xadmin
from apps.courses.models import Course, Lesson, Video, CourseResource
class GlobalSettings(object):
site_title = '慕学后台管理系统' # 修改名称
site_footer = '慕学在线网' # 修改footer
# menu_style = 'accordion' # 左侧apps是否默认折叠并显示数量
class BaseSettings(object):
# 增加修改主题选项
enable_themes = True
use_bootswatch = True
# xadmin允许我们不继承任何东西
class CourseAdmin(object):
list_display = ['name', 'desc', 'detail', 'degree', 'learn_times', 'students']
search_fields = ['name', 'desc', 'detail', 'degree', 'students']
list_filter = ['name', 'teacher__name', 'desc', 'detail', 'degree', 'learn_times', 'students']
list_editable = ["degree", "desc"]
class LessonAdmin(object):
list_display = ['course', 'name', 'add_time']
search_fields = ['course', 'name']
list_filter = ['course__name', 'name', 'add_time']
class VideoAdmin(object):
list_display = ['lesson', 'name', 'add_time']
search_fields = ['lesson', 'name']
list_filter = ['lesson', 'name', 'add_time']
class CourseResourceAdmin(object):
list_display = ['course', 'name', 'file', 'add_time']
search_fields = ['course', 'name', 'file']
list_filter = ['course', 'name', 'file', 'add_time']
xadmin.site.register(Course, CourseAdmin)
xadmin.site.register(Lesson, LessonAdmin)
xadmin.site.register(Video, VideoAdmin)
xadmin.site.register(CourseResource, CourseResourceAdmin)
xadmin.site.register(xadmin.views.CommAdminView, GlobalSettings)
xadmin.site.register(xadmin.views.BaseAdminView, BaseSettings)
总结
1.list_filter = ['name', 'teacher__name', 'desc', 'detail', 'degree', 'learn_times', 'students']
对于外键的过滤,我们要使用双下划线teacher__name
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。