from django.db import models from django.template.defaultfilters import slugify from django.contrib.sitemaps import Sitemap from utils.util import markdown_to_html, render_images class Page(models.Model): title = models.CharField(max_length=200) slug = models.SlugField() body_html = models.TextField(blank=True) body_markdown = models.TextField() meta_description = models.CharField(max_length=256, null=True, blank=True) path = models.CharField(max_length=200, null=True, blank=True) def __str__(self): return self.title def get_absolute_url(self): if self.path: return "/%s/%s" % (self.path, self.slug) else: return "/%s" % (self.slug) def save(self): # run markdown md = render_images(self.body_markdown) self.body_html = markdown_to_html(md) if not self.id: # self.date_created = timezone.now() self.slug = slugify(self.title)[:50] super(Page, self).save() class PageSitemap(Sitemap): changefreq = "never" priority = 1.0 protocol = "https" def items(self): return Page.objects.all()