khaganat-web/pages/models.py

39 lines
1.1 KiB
Python
Raw Normal View History

2018-01-13 14:45:54 +00:00
from django.conf import settings
from django.db import models
2018-02-25 19:46:41 +00:00
import markdown
2018-01-13 14:45:54 +00:00
class Page(models.Model):
slug = models.CharField(max_length=200, unique=True)
default = models.BooleanField(default=False)
2018-06-02 14:03:13 +00:00
is_nsfw = models.BooleanField(default=False)
2018-01-13 14:45:54 +00:00
def __str__(self):
return self.slug
2018-01-27 22:12:09 +00:00
2018-01-13 14:45:54 +00:00
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()
2018-02-25 19:46:41 +00:00
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',
)
2018-01-13 14:45:54 +00:00
def __str__(self):
return self.title