(1)在users下面创建adminx.py,代码如下:
# users/adminx.py import xadmin from .models import EmailVerifyRecord #xadmin中这里是继承object,不再是继承admin
class EmailVerifyRecordAdmin(object): # 显示的列 list_display = ['code', 'email', 'send_type', 'send_time'] # 搜索的字段,不要添加时间搜索 search_fields = ['code', 'email', 'send_type'] # 过滤 list_filter = ['code', 'email', 'send_type', 'send_time'] xadmin.site.register(EmailVerifyRecord,EmailVerifyRecordAdmin)
users中Banner也注册进去
class BannerAdmin(object): list_display = ['title', 'image', 'url','index', 'add_time'] search_fields = ['title', 'image', 'url','index'] list_filter = ['title', 'image', 'url','index', 'add_time'] xadmin.site.register(Banner,BannerAdmin)
app注册:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# users/adminx.py import xadmin from .models import EmailVerifyRecord,Banner #xadmin中这里是继承object,不再是继承admin class EmailVerifyRecordAdmin(object): # 显示的列 list_display = ['code', 'email', 'send_type', 'send_time'] # 搜索的字段 search_fields = ['code', 'email', 'send_type'] # 过滤 list_filter = ['code', 'email', 'send_type', 'send_time'] class BannerAdmin(object): list_display = ['title', 'image', 'url','index', 'add_time'] search_fields = ['title', 'image', 'url','index'] list_filter = ['title', 'image', 'url','index', 'add_time'] xadmin.site.register(EmailVerifyRecord,EmailVerifyRecordAdmin) xadmin.site.register(Banner,BannerAdmin) users/adminx.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# course/adminx.py import xadmin from .models import Course, Lesson, Video, CourseResource # Course的admin管理器 class CourseAdmin(object): '''课程''' list_display = [ 'name','desc','detail','degree','learn_times','students'] search_fields = ['name', 'desc', 'detail', 'degree', 'students'] list_filter = [ 'name','desc','detail','degree','learn_times','students'] class LessonAdmin(object): '''章节''' list_display = ['course', 'name', 'add_time'] search_fields = ['course', 'name'] #这里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', 'download', 'add_time'] search_fields = ['course', 'name', 'download'] list_filter = ['course__name', 'name', 'download', 'add_time'] # 将管理器与model进行注册关联 xadmin.site.register(Course, CourseAdmin) xadmin.site.register(Lesson, LessonAdmin) xadmin.site.register(Video, VideoAdmin) xadmin.site.register(CourseResource, CourseResourceAdmin) course/adminx.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# organization/adminx.py import xadmin from .models import CityDict, CourseOrg, Teacher class CityDictAdmin(object): '''城市''' list_display = ['name', 'desc', 'add_time'] search_fields = ['name', 'desc'] list_filter = ['name', 'desc', 'add_time'] class CourseOrgAdmin(object): '''机构''' list_display = ['name', 'desc', 'click_nums', 'fav_nums','add_time' ] search_fields = ['name', 'desc', 'click_nums', 'fav_nums'] list_filter = ['name', 'desc', 'click_nums', 'fav_nums','city__name','address','add_time'] class TeacherAdmin(object): '''老师''' list_display = [ 'name','org', 'work_years', 'work_company','add_time'] search_fields = ['org', 'name', 'work_years', 'work_company'] list_filter = ['org__name', 'name', 'work_years', 'work_company','click_nums', 'fav_nums', 'add_time'] xadmin.site.register(CityDict, CityDictAdmin) xadmin.site.register(CourseOrg, CourseOrgAdmin) xadmin.site.register(Teacher, TeacherAdmin) organization/adminx.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# operation/adminx.py import xadmin from .models import UserAsk, UserCourse, UserMessage, CourseComments, UserFavorite class UserAskAdmin(object): '''用户表单我要学习''' list_display = ['name', 'mobile', 'course_name', 'add_time'] search_fields = ['name', 'mobile', 'course_name'] list_filter = ['name', 'mobile', 'course_name', 'add_time'] # class UserCourseAdmin(object): '''用户课程学习''' list_display = ['user', 'course', 'add_time'] search_fields = ['user', 'course'] list_filter = ['user', 'course', 'add_time'] class UserMessageAdmin(object): '''用户消息后台''' list_display = ['user', 'message', 'has_read', 'add_time'] search_fields = ['user', 'message', 'has_read'] list_filter = ['user', 'message', 'has_read', 'add_time'] class CourseCommentsAdmin(object): '''用户评论后台''' list_display = ['user', 'course', 'comments', 'add_time'] search_fields = ['user', 'course', 'comments'] list_filter = ['user', 'course', 'comments', 'add_time'] class UserFavoriteAdmin(object): '''用户收藏后台''' list_display = ['user', 'fav_id', 'fav_type', 'add_time'] search_fields = ['user', 'fav_id', 'fav_type'] list_filter = ['user', 'fav_id', 'fav_type', 'add_time'] # 将后台管理器与models进行关联注册。 xadmin.site.register(UserAsk, UserAskAdmin) xadmin.site.register(UserCourse, UserCourseAdmin) xadmin.site.register(UserMessage, UserMessageAdmin) xadmin.site.register(CourseComments, CourseCommentsAdmin) xadmin.site.register(UserFavorite, UserFavoriteAdmin) operation/adminx.py
最后的结果是运行程序,进入后台可以看到侧边栏添加追加了的app信息。