khaganat-web/pages/models.py
2018-06-02 16:03:13 +02:00

38 lines
1.1 KiB
Python

from django.conf import settings
from django.db import models
import markdown
class Page(models.Model):
slug = models.CharField(max_length=200, unique=True)
default = models.BooleanField(default=False)
is_nsfw = models.BooleanField(default=False)
def __str__(self):
return self.slug
class PageContent(models.Model):
page = models.ForeignKey(Page, on_delete=models.CASCADE)
language = models.CharField(max_length=10, choices=settings.LANGUAGES)
created_on = models.DateTimeField(auto_now_add=True)
edited_on = models.DateTimeField(auto_now=True)
title = models.CharField(max_length=200)
content = models.TextField()
def formated_content(self):
return markdown.markdown(
self.content,
extensions=[
'markdown.extensions.extra',
'markdown.extensions.admonition',
'markdown.extensions.nl2br',
'markdown.extensions.sane_lists',
'markdown.extensions.smarty',
'markdown.extensions.toc',
],
output_format='html5',
)
def __str__(self):
return self.title