class Group(models.Model):
title = models.CharField(max_length=200,
verbose_name='Категория')
slug = models.SlugField(max_length=255,
unique=True,
verbose_name='Параметр')
description = models.TextField(verbose_name='Описание')
def __str__(self):
return self.title
class Meta:
verbose_name = 'Категория'
verbose_name_plural = 'Категории'
ordering = ('category',)
class Post(models.Model):
text = models.TextField(verbose_name='Содержание')
pub_date = models.DateTimeField(auto_now_add=True,
verbose_name='Дата создания')
group = models.ForeignKey('Group',
blank=True,
null=True,
on_delete=models.SET_NULL,
related_name='posts',
verbose_name='Категория')
author = models.ForeignKey(User,
on_delete=models.CASCADE,
related_name='posts',
verbose_name='Автор')
def __str__(self):
return self.text.join(self.text.split(' ')[:20]) + " ->>"
class Meta:
verbose_name = 'Статья'
verbose_name_plural = 'Статьи'
ordering = ('-pub_date', 'author')