注册users应用模型
编辑users应用下的admin.py
from django.contrib import admin
from .models import UserProfile, VerifyCode
class UserProfileAdmin(admin.ModelAdmin):
list_display = ['id', 'username', 'nickname', 'mobile', 'is_staff', 'is_active']
class VerifyCodeAdmin(admin.ModelAdmin):
list_display = ['id', 'code', 'add_time']
admin.site.register(UserProfile, UserProfileAdmin)
admin.site.register(VerifyCode, VerifyCodeAdmin)
运行Tools->Run manage.py Task,创建超级管理员并设置用户名、邮箱、密码
manage.py@LehuXuexi > createsuperuser
用户名: admin
电子邮件地址: admin@lehu.com
Warning: Password input may be echoed.
Password: admin123456
Warning: Password input may be echoed.
Password (again): admin123456
Superuser created successfully.
接下来run或者debug运行项目,在浏览器输入 http://localhost:8000/admin
输入账密进入后台管理系统
Performing system checks...
System check identified no issues (0 silenced).
January 04, 2020 - 16:30:54
Django version 2.2.6, using settings 'LehuXuexi.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
把其他应用的模型都注册到后台
blogs应用下的admin.py
from django.contrib import admin
from .models import BlogCategory, BlogTag, Article
class BlogCategoryAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'add_time']
class BlogTagAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'add_time']
class ArticleAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'category', 'user', 'click_num', 'add_time']
list_filter = ['category', 'user', 'add_time']
admin.site.register(BlogTag, BlogTagAdmin)
admin.site.register(BlogCategory, BlogCategoryAdmin)
admin.site.register(Article, ArticleAdmin)
courses应用下的admin.py
from django.contrib import admin
from .models import CourseCategory, Course
class CourseCategoryAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'add_time']
class CourseAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'category', 'school', 'teacher', 'degree', 'add_time']
admin.site.register(CourseCategory, CourseCategoryAdmin)
admin.site.register(Course, CourseAdmin)
orgs应用下的admin.py
from django.contrib import admin
from .models import School, Teacher
class SchoolAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'click_num', 'favor_num', 'add_time']
class TeacherAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'school', 'features', 'add_time']
admin.site.register(School, SchoolAdmin)
admin.site.register(Teacher, TeacherAdmin)
版权声明:如无特殊说明,文章均为本站原创,转载请注明出处
本文链接:http://zhangyanc.club/subject/article/django-admin/
许可协议:署名-非商业性使用 4.0 国际许可协议