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.
31 lines
709 B
31 lines
709 B
2 years ago
|
from django.db import models
|
||
|
from django.utils import timezone
|
||
|
from article.models import Article
|
||
|
from django.contrib.auth.models import User
|
||
|
|
||
|
|
||
|
class Comment(models.Model):
|
||
|
# 评论人
|
||
|
author = models.ForeignKey(
|
||
|
User,
|
||
|
on_delete=models.CASCADE,
|
||
|
related_name='comments',
|
||
|
)
|
||
|
# 文章
|
||
|
article = models.ForeignKey(
|
||
|
Article,
|
||
|
on_delete=models.CASCADE,
|
||
|
related_name='comments',
|
||
|
)
|
||
|
# 评论内容
|
||
|
content = models.TextField()
|
||
|
# 评论时间
|
||
|
created = models.DateTimeField(default=timezone.now)
|
||
|
|
||
|
class Meta:
|
||
|
ordering = ['-created']
|
||
|
|
||
|
def __str__(self):
|
||
|
# 展示前20个字符
|
||
|
return self.content[:20]
|