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)
相关推荐
测试员周周2 分钟前
【AI测试智能体-面试】AI测试面试60题(附回答思路)
人工智能·python·功能测试·测试工具·单元测试·自动化·测试用例
sensen_kiss9 分钟前
CPT304 SoftwareEngineeringII 软件工程 2 Pt.8 软件测试 (Software Testing)(上)
学习·软件工程
力学与人工智能11 分钟前
PPT分享 | 洛桑联邦理工学院魏震:深度几何学习在工业设计优化中的应用
学习·优化·工业设计·深度几何学习·洛桑联邦理工学院
用户83562907805121 分钟前
使用 Python 操作 Word 评论和回复
后端·python
Zella折耳根40 分钟前
复习篇-继承和接口
java·开发语言·python
诗词在线43 分钟前
求推荐飞花令
大数据·人工智能·python
yijianace1 小时前
Python线程与多线程完全总结(从入门到理解并发本质)
开发语言·python
sensen_kiss2 小时前
CPT304 SoftwareEngineeringII 软件工程 2 Pt.9 软件测试 (Software Testing)(下)
学习·软件工程
会Tk矩阵群控的小木2 小时前
基于Python的iMessage短信群发与社媒多账号统一管理系统实现
开发语言·windows·python·新媒体运营·开源软件·个人开发
wu_ye_m2 小时前
学习c语言第35天 函数声明和定义
c语言·开发语言·学习