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.
29 lines
835 B
29 lines
835 B
from django.db import models |
|
import re |
|
|
|
|
|
class Post(models.Model): |
|
"""Класс записи в блоге.""" |
|
|
|
title = models.CharField(max_length=250) |
|
text = models.TextField() |
|
pub_date = models.DateTimeField("date published") |
|
|
|
@property |
|
def org_text(self): |
|
"""Вернет text заменив html на org.""" |
|
text = self.text |
|
text = re.sub(r"(<strong>(.+?)</strong>)", r"\*\2\*") |
|
return text |
|
|
|
def __str__(self): |
|
return self.title |
|
|
|
def save(self, *args, **kwargs): |
|
self.text = re.sub(r"(\n.+?\n)", r"<p>\1</p> ", self.text) |
|
self.text = re.sub(r"(\*(.+?)\*)", r"<strong>\2</strong>", self.text) |
|
super(Post, self).save(*args, **kwargs) |
|
|
|
class Meta: |
|
verbose_name = "Статья" |
|
verbose_name_plural = "Статьи"
|
|
|