You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
from django . contrib import admin
# Register your models here.
# 本文件用于将数据模型注册到 Django 管理后台( Admin) , 并自定义其展示和操作方式。
# 当前未立即注册模型,需在下方通过 admin.site.register() 显式注册。
class CommandsAdmin ( admin . ModelAdmin ) :
"""
Django Admin 配置类,用于自定义 ' commands ' 模型在管理后台中的列表展示。
控制在模型列表页面显示哪些字段。
"""
# 定义在管理后台的模型列表页面中要显示的字段列
# 用户将看到三列:'title'(命令标题)、'command'(命令内容)、'describe'(描述)
list_display = ( ' title ' , ' command ' , ' describe ' )
class EmailSendLogAdmin ( admin . ModelAdmin ) :
"""
Django Admin 配置类,用于自定义 ' EmailSendLog ' 模型在管理后台中的行为。
该日志模型主要用于查看,禁止添加新记录,并将所有字段设为只读。
"""
# 定义在管理后台的模型列表页面中要显示的字段列
# 显示:邮件标题、收件人、发送结果、创建时间
list_display = ( ' title ' , ' emailto ' , ' send_result ' , ' creation_time ' )
# 定义在编辑或查看单条记录时,哪些字段为只读(不可编辑)
# 所有字段均设为只读,防止日志被意外修改
readonly_fields = (
' title ' ,
' emailto ' ,
' send_result ' ,
' creation_time ' ,
' content '
)
# 重写权限方法,禁止用户在管理后台添加新的 EmailSendLog 记录
# 因为邮件日志应由程序自动创建,不允许手动添加
#
# 参数:
# request: 当前的 HTTP 请求对象
#
# 返回:
# bool: 始终返回 False, 表示禁止添加操作
def has_add_permission ( self , request ) :
return False