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)
相关推荐
M--Y34 分钟前
LangGraph 工作流模式
开发语言·javascript·python·langchain·大模型·llm·langgraph
岁月宁静1 小时前
DeepSeek Harness 实战与架构解析:让 Agent 从“会聊”到“能交付”
人工智能·python·agent
LiaoWL1231 小时前
NumPy 入门实战(二):向量化与余弦相似度——从 ndarray 到 Embedding
python·numpy·embedding
forest_092 小时前
多 Agent 协作第二课:交叉验证≠独立验证
人工智能·python·算法·机器学习·prompt·agi
小杨小杨、努力变强!2 小时前
python学习笔记
笔记·学习
databook5 小时前
时间序列数据,先拆规律还是先查异常
python·数据挖掘·数据分析
师夷长技以自愈5 小时前
手搓 AI Agent 第 8 篇:从手写循环到画流程图——LangGraph 封装
人工智能·python
aifannihao6 小时前
Rust 1.100 的 DropGuard:用 Python 实测失败回滚与吞异常
python·rust·异常处理·标准库·contextlib
Star(up up up)7 小时前
Redis Windows 安装教程:使用Windows 的 Redis 压缩包
redis·笔记·学习·程序人生·云原生·学习方法·改行学it
用户019027581618 小时前
天勤 tqsdk 能做 A 股行情吗?期货强项与股票数据选型
python