Django学习-后台管理相关操作

admin配置步骤:

注册自定义的模型类:

代码:

python 复制代码
from django.contrib import admin
from .models import Book, Author

# Register your models here.
admin.site.register(Book)
admin.site.register(Author)

模型管理器类(修改):

admin.py:

python 复制代码
from django.contrib import admin
from .models import Book, Author

#  Register your models here.
# admin.site.register(Book)
# admin.site.register(Author)


class BookManager(admin.ModelAdmin):
    # 列表页显示的字段
    list_display = ['id', 'title', 'pub', 'price', 'market_price', 'is_active']
    # 列表页可以点击进入编辑界面的字段
    list_display_links = ['id', 'title']
    # 列表页可以直接编辑的字段
    list_editable = ['price']
    # 列表页右侧增加搜索框
    search_fields = ['price']
    # 列表页右侧增加过滤器
    list_filter = ['is_active']

admin.site.register(Book, BookManager)
相关推荐
TF男孩17 小时前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
该用户已不存在1 天前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP1 天前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
用户8356290780511 天前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
c8i1 天前
python中类的基本结构、特殊属性于MRO理解
python
liwulin05061 天前
【ESP32-CAM】HELLO WORLD
python
2303_Alpha1 天前
SpringBoot
笔记·学习
萘柰奈1 天前
Unity学习----【进阶】TextMeshPro学习(三)--进阶知识点(TMP基础设置,材质球相关,两个辅助工具类)
学习·unity
Doris_20231 天前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_20231 天前
Python 模式匹配match case
前端·后端·python