import re from django.db import models from django.contrib.sitemaps import Sitemap from django.contrib.sites.models import Site from media.models import LuxImage from posts.models import Post from utils.util import markdown_to_html, render_images class Page(models.Model): title = models.CharField(max_length=200) sub_title = models.CharField(max_length=300, blank=True) slug = models.SlugField() body_html = models.TextField(blank=True) body_markdown = models.TextField() meta_description = models.CharField(max_length=256, blank=True) path = models.CharField(max_length=200, blank=True) app = models.CharField(max_length=50, blank=True) build = models.BooleanField(default=True) enable_comments = models.BooleanField(default=False) site = models.ForeignKey(Site, on_delete=models.CASCADE) featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) pub_date = models.DateTimeField('Date published', 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) super(Page, self).save() class HomePage(models.Model): """ simple model to control the featured article on the homepage also allows me to fudge the "popular" section to be what I want """ featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) tag_line = models.CharField(max_length=200, null=True, blank=True) featured = models.ForeignKey(Post, on_delete=models.CASCADE, related_name="banner", null=True, blank=True) #popular = models.ManyToManyField(Post, related_name="popular") template_name = models.CharField(max_length=200, help_text="full path", null=True, blank=True) class PageSitemap(Sitemap): changefreq = "never" priority = 1.0 protocol = "https" def items(self): return Page.objects.filter(build=True)