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)
相关推荐
ASKED_20191 小时前
Langchain学习笔记一 -基础模块以及架构概览
笔记·学习·langchain
好家伙VCC1 小时前
### WebRTC技术:实时通信的革新与实现####webRTC(Web Real-TimeComm
java·前端·python·webrtc
(❁´◡`❁)Jimmy(❁´◡`❁)2 小时前
Exgcd 学习笔记
笔记·学习·算法
前端玖耀里2 小时前
如何使用python的boto库和SES发送电子邮件?
python
serve the people2 小时前
python环境搭建 (十二) pydantic和pydantic-settings类型验证与解析
java·网络·python
小天源2 小时前
Error 1053 Error 1067 服务“启动后立即停止” Java / Python 程序无法后台运行 windows nssm注册器下载与报错处理
开发语言·windows·python·nssm·error 1053·error 1067
云小逸3 小时前
【nmap源码学习】 Nmap网络扫描工具深度解析:从基础参数到核心扫描逻辑
网络·数据库·学习
喵手3 小时前
Python爬虫实战:HTTP缓存系统深度实战 — ETag、Last-Modified与requests-cache完全指南(附SQLite持久化存储)!
爬虫·python·爬虫实战·http缓存·etag·零基础python爬虫教学·requests-cache
喵手3 小时前
Python爬虫实战:容器化与定时调度实战 - Docker + Cron + 日志轮转 + 失败重试完整方案(附CSV导出 + SQLite持久化存储)!
爬虫·python·爬虫实战·容器化·零基础python爬虫教学·csv导出·定时调度
2601_949146533 小时前
Python语音通知接口接入教程:开发者快速集成AI语音API的脚本实现
人工智能·python·语音识别