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)
相关推荐
qq_2147826112 分钟前
GWalkR,部分替代Tableau!
ide·python·jupyter
Yuner200021 分钟前
Python机器学习:从零基础到深度实战
人工智能·python·机器学习
speop24 分钟前
【datawhale组队学习】TASK01|课程导论:站在认知范式的临界点
人工智能·学习
r i c k36 分钟前
办公小程序开发----提高工作效率
python·python程序开发
wha the fuck40436 分钟前
(渗透脚本)TCP创建连接脚本----解题----极客大挑战2019HTTP
python·网络协议·tcp/ip·网络安全·脚本书写
qq_3561969537 分钟前
day39模型的可视化和推理@浙大疏锦行
python
深蓝电商API43 分钟前
从 “能爬” 到 “稳爬”:Python 爬虫中级核心技术实战
开发语言·爬虫·python
roman_日积跬步-终至千里1 小时前
【人工智能原理(1)】要点总结:从搜索、学习到推理的智能之路
人工智能·学习
czlczl200209251 小时前
如何添加“默认给Sql查询语句加上租户条件”的功能
数据库·python·sql
破烂pan1 小时前
Python 长连接实现方式全景解析
python·websocket·sse