master
徐锦泽 4 months ago
parent 5a940dd6f1
commit 68390aa876

@ -29,8 +29,6 @@ class CommentAdmin(admin.ModelAdmin):
list_filter = ('is_enable',)
exclude = ('creation_time', 'last_modify_time')
actions = [disable_commentstatus, enable_commentstatus]
raw_id_fields = ('author', 'article')
search_fields = ('body',)
def link_to_userinfo(self, obj):
info = (obj.author._meta.app_label, obj.author._meta.model_name)

@ -1,5 +1,7 @@
from django.conf import settings
# xjz: 评论系统数据模型模块
# xjz: 定义评论相关的数据库模型和数据结构
from django.db import models
from django.conf import settings
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
@ -7,19 +9,26 @@ from blog.models import Article
# Create your models here.
# xjz: 评论模型类
# xjz: 存储用户对文章的评论信息,包括内容、时间等
class Comment(models.Model):
# xjz: 评论内容正文Text类型支持长文本
body = models.TextField('正文', max_length=300)
# xjz: 评论创建时间,自动记录创建时刻
creation_time = models.DateTimeField(_('creation time'), default=now)
# xjz: 评论最后修改时间,记录最后编辑时刻
last_modify_time = models.DateTimeField(_('last modify time'), default=now)
# xjz: 评论作者,外键关联用户模型
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
verbose_name=_('author'),
on_delete=models.CASCADE)
# xjz: 所属文章,外键关联博客文章
article = models.ForeignKey(
Article,
verbose_name=_('article'),
on_delete=models.CASCADE)
# xjz: 父级评论,支持评论回复功能,允许为空
parent_comment = models.ForeignKey(
'self',
verbose_name=_('parent comment'),
@ -28,9 +37,11 @@ class Comment(models.Model):
on_delete=models.CASCADE)
is_enable = models.BooleanField(_('enable'),
default=False, blank=False, null=False)
# xjz: Comment模型的元数据配置
class Meta:
# xjz: 按ID降序排列新的评论显示在前面
ordering = ['-id']
# xjz: 在管理后台显示的名称
verbose_name = _('comment')
verbose_name_plural = verbose_name
get_latest_by = 'id'

Loading…
Cancel
Save