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)
相关推荐
CodeGL5 分钟前
10、Python基础之进程和线程
开发语言·python
Young Doro1 小时前
独立性检测学习任务
人工智能·学习·数据挖掘
TechWayfarer1 小时前
PHP漏洞被利用,怎么揪出攻击IP?
开发语言·python·tcp/ip·网络安全·php
2601_967980112 小时前
Python列表操作方法详解
python·数据类型·修改·列表操作·功能汇总
卡卡~~2 小时前
“101计划”核心课程实践教材《数据实验结构指导-C++语言版》题目集
开发语言·c++·学习·算法
Patrick在香港3 小时前
台风在变少,来香港的没有
python·数据分析·香港·开放数据·热带气旋
qq_406981033 小时前
大白话rust系列09 函数调用两次有什么错?
开发语言·python·rust
benchmark_cc3 小时前
QuantDash 安装成功后,如何验证 Python 环境可以正常导入 SDK?
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
lengxuenong4 小时前
树状数组 · 信息学学习手册1-求和3个模板
c++·学习·算法·青少年编程
zh路西法4 小时前
【模型式强化学习】(二)PETS——从概率动力学模型到模型预测控制(MPC)
pytorch·python·强化学习·pe·mpc·ces·pets