class Post(models.Model):
title = models.CharField(max_length=150, db_index=True, verbose_name='Заголовок')
body = models.TextField(verbose_name='Текст поста')
author = models.ForeignKey(AdvancedUser, on_delete=models.PROTECT, verbose_name='Автор', related_name='posts')
post_date = models.DateTimeField(auto_now=True, verbose_name='Дата публикации')
def __str__(self):
return self.title
class Meta:
verbose_name = 'Пост'
verbose_name_plural = 'Посты'
ordering = ('-post_date',)
class Comment(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE, verbose_name='Пост')
author = models.ForeignKey(AdvancedUser, on_delete=models.PROTECT, verbose_name='Автор')
comment_date = models.DateTimeField(auto_now_add=True, verbose_name='Дата комментария')
comment_text = models.TextField(verbose_name='Комментарий', help_text='Допускается использование HTML разметки.')
def __str__(self):
return f'Comment to {self.post} post'
class Meta:
ordering = ('comment_date',)