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)
相关推荐
Hockor1 分钟前
写给前端的 Python 教程四(列表/元组)
前端·后端·python
这里有鱼汤10 分钟前
熟练掌握MACD这8种形态,让你少走三年弯路(附Python量化代码)| 建议收藏
后端·python
404.Not Found19 分钟前
Day46 Python打卡训练营
开发语言·python
love530love21 分钟前
【PyCharm必会基础】正确移除解释器及虚拟环境(以 Poetry 为例 )
开发语言·ide·windows·笔记·python·pycharm
凌辰揽月22 分钟前
Web后端基础(基础知识)
java·开发语言·前端·数据库·学习·算法
运维开发王义杰28 分钟前
Python: 告别 ModuleNotFoundError, 解决 pipx 环境下 sshuttle 缺少 pydivert 依赖的终极指南
开发语言·python
DanCheng-studio1 小时前
毕设 基于机器视觉的驾驶疲劳检测系统(源码+论文)
python·毕业设计·毕设
carpell1 小时前
【语义分割专栏】3:Segnet实战篇(附上完整可运行的代码pytorch)
人工智能·python·深度学习·计算机视觉·语义分割
一只小波波呀2 小时前
打卡第48天
python
whoarethenext2 小时前
C++ OpenCV 学习路线图
c++·opencv·学习