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.
# 导入Django管理模块
from django . contrib import admin
# 导入自定义模型( 假设已在同一目录的models.py中定义)
from . models import commands , EmailSendLog
# 注册Commands模型到Django管理后台
class CommandsAdmin ( admin . ModelAdmin ) :
"""
命令模型的管理界面配置类
用于自定义commands模型在Django admin中的显示和行为
"""
# 设置在管理列表页面显示的字段
list_display = ( ' title ' , ' command ' , ' describe ' )
# 字段说明:
# - title: 命令标题
# - command: 具体命令内容
# - describe: 命令描述
# 注册EmailSendLog模型到Django管理后台
class EmailSendLogAdmin ( admin . ModelAdmin ) :
"""
邮件发送日志模型的管理界面配置类
用于自定义EmailSendLog模型在Django admin中的显示和行为
"""
# 设置在管理列表页面显示的字段
list_display = ( ' title ' , ' emailto ' , ' send_result ' , ' creation_time ' )
# 字段说明:
# - title: 邮件标题
# - emailto: 收件人
# - send_result: 发送结果
# - creation_time: 创建时间
# 设置只读字段,这些字段在编辑页面不可修改
readonly_fields = (
' title ' , # 邮件标题(只读)
' emailto ' , # 收件人(只读)
' send_result ' , # 发送结果(只读)
' creation_time ' , # 创建时间(只读)
' content ' # 邮件内容(只读)
)
def has_add_permission ( self , request ) :
"""
重写添加权限方法,禁止在管理后台手动添加邮件日志记录
Args:
request: HTTP请求对象
Returns:
bool: 总是返回False, 禁止添加操作
"""
return False
# 这样设计是因为邮件发送日志应该由系统自动创建
# 而不是手动添加,保证日志的真实性和完整性
# 将模型注册到Django管理后台
admin . site . register ( commands , CommandsAdmin )
admin . site . register ( EmailSendLog , EmailSendLogAdmin )