什么是admin管理后台
配置步骤
添加组
增加用户
对自定义表进行操作
注册自定义模型类
bookstore/admin.py
from django.contrib import admin
from .models import Book
# Register your models here.
#
admin.site.register(Book)
![image](https://www.icode9.com/i/l/?n=20&i=blog/1847830/202108/1847830-20210813091100380-
1343933388.png)
显示样式与__str__相同
模型管理器类
list_display
from django.contrib import admin
from .models import Book
# Register your models here.
#
class BookMaage(admin.ModelAdmin):
list_display=['id','title','pub','price']
admin.site.register(Book,BookMaage)
显示列名参数verbose_name
list_filter添加过滤器
from django.contrib import admin
from .models import Book
# Register your models here.
class BookMaage(admin.ModelAdmin):
list_display=['id','title','pub','price']
#过滤器 分类查询
list_filter=['pub']
admin.site.register(Book,BookMaage)
search_fields
from django.contrib import admin
from .models import Book
# Register your models here.
#
class BookMaage(admin.ModelAdmin):
list_display=['id','title','pub','price']
#添加搜索框[模糊搜索]
search_fields=['title']
admin.site.register(Book,BookMaage)
添加可编辑字段 list_editable
from django.contrib import admin
from .models import Book
# Register your models here.
#
class BookMaage(admin.ModelAdmin):
list_display=['id','title','pub','price']
#控制 list_display中的字段,可以链接到修改页 ,必须是list_display中
list_display_links=['title']
#过滤器 分类查询
list_filter=['pub']
#添加搜索框[模糊搜索]
search_fields=['title']
#添加可编辑字段
list_editable=['price']
admin.site.register(Book,BookMaage)