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.
abc/src/comments/models.py

51 lines
1.9 KiB

This file contains ambiguous Unicode characters!

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.

# 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 _
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'),
blank=True,
null=True,
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'
def __str__(self):
return self.body