python-admin管理后台
2021/8/15 22:07:03
本文主要是介绍python-admin管理后台,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
什么是admin管理后台
配置步骤
添加组
增加用户
对自定义表进行操作
注册自定义模型类
bookstore/admin.py
from django.contrib import admin from .models import Book # Register your models here. # admin.site.register(Book)
![image](https://www.www.zyiz.net/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)
这篇关于python-admin管理后台的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Python基础编程
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南