django有一个admin站点,将模型注册到admin后,有一个页面可以进行管理
myApp/admin.py
# Register your models here.
from .models import Grade,Student
class GradeAdmin(admin.ModelAdmin):
# 列表页属性
list_display = ['pk','gname','gdate','ggirlnum','gboynum','isDelete']
list_filter = ['gname']#增加以gname字段筛选的过滤器
search_fields = ['gname']#增加gname字段搜索功能
list_per_page = 10
# 添加修改页属性
# fields = ['ggirlnum','gboynum','gname']#指定添加修改页面的字段先后顺序
fieldsets = [
("num",{"fields":['ggirlnum','gboynum']}),
("base",{"fields":['gname','gdate','isDelete']}),
]
admin.site.register(Grade,GradeAdmin)
admin.site.register(Student)
网友评论