update. 完成前端页面展示、列表和详情页
update. 调整融合主菜单与板块 update. 分离新闻模块
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
|
||||
from .models import NewsSection, News
|
||||
|
||||
|
||||
# Register your models here.
|
||||
|
||||
|
||||
# --- 1. 板块管理配置 ---
|
||||
@admin.register(NewsSection)
|
||||
class NewsSectionAdmin(ImportExportModelAdmin):
|
||||
list_display = ('name', 'code', 'order', 'enabled') # 列表显示的字段
|
||||
list_editable = ('order', 'enabled') # 允许直接在列表页修改排序和状态
|
||||
search_fields = ('name', 'code') # 搜索框
|
||||
prepopulated_fields = {'code': ('name',)} # 输入名称时自动生成 Slug
|
||||
ordering = ('order', 'name') # 默认排序
|
||||
|
||||
|
||||
# --- 2. 文章管理配置 ---
|
||||
@admin.register(News)
|
||||
class NewsAdmin(ImportExportModelAdmin):
|
||||
# 列表页显示
|
||||
list_display = ('title', 'section', 'author', 'is_published', 'created_at', 'updated_at')
|
||||
list_filter = ('section', 'is_published', 'created_at', 'author') # 右侧过滤器
|
||||
search_fields = ('title', 'content') # 搜索框(支持搜标题和内容)
|
||||
date_hierarchy = 'created_at' # 顶部日期层级导航
|
||||
ordering = ('-created_at',) # 按创建时间倒序
|
||||
|
||||
# 编辑页布局
|
||||
fieldsets = (
|
||||
('基本信息', {
|
||||
'fields': ('title', 'section', 'author', 'is_published')
|
||||
}),
|
||||
('内容', {
|
||||
# CKEditor5Field 会自动渲染为富文本编辑器,无需额外配置 widget
|
||||
'fields': ('content', 'cover'),
|
||||
'classes': ('wide',) # wide 类可以让编辑器占据更多宽度
|
||||
}),
|
||||
('系统信息', {
|
||||
'fields': ('created_at', 'updated_at'),
|
||||
'classes': ('collapse', 'extrapretty'), # collapse 默认折叠,extrapretty 美化
|
||||
'description': '只读信息,自动生成'
|
||||
}),
|
||||
)
|
||||
|
||||
# 只读字段(系统自动生成的字段)
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
|
||||
# 自动填充 Slug(如果以后给 News 加 slug 字段可以用)
|
||||
# prepopulated_fields = {'slug': ('title',)}
|
||||
Reference in New Issue
Block a user