diff options
Diffstat (limited to 'app/posts/models.py')
-rw-r--r-- | app/posts/models.py | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/app/posts/models.py b/app/posts/models.py index 2ad995d..2726949 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -76,6 +76,12 @@ class PostType(models.IntegerChoices): FIELD_NOTE = 5, ('field note') GUIDE = 6, ('guide') FILM = 7, ('film') + HOWTO = 8, ('how to') + +class PostTopic(models.IntegerChoices): + SPIRIT = 0, ('spirit') + CRAFT = 1, ('craft') + TOOLS = 2, ('tools') class Post(models.Model): @@ -101,16 +107,8 @@ class Post(models.Model): ) status = models.IntegerField(choices=PUB_STATUS, default=0) featured_image = models.ForeignKey(LuxImage, on_delete=models.SET_NULL, null=True, blank=True) - TEMPLATES = ( - (0, 'single'), - (1, 'double'), - (2, 'single-dark'), - (3, 'double-dark'), - (4, 'single-black'), - (5, 'double-black'), - ) post_type = models.IntegerField(choices=PostType.choices, default=PostType.JRNL) - template_name = models.IntegerField(choices=TEMPLATES, default=0) + post_topic = models.IntegerField(choices=PostTopic.choices, default=PostTopic.SPIRIT) has_video = models.BooleanField(blank=True, default=False) has_code = models.BooleanField(blank=True, default=False) disclaimer = models.BooleanField(blank=True, default=False) @@ -138,15 +136,12 @@ class Post(models.Model): return reverse('film:detail', kwargs={"slug": self.slug}) if self.post_type == PostType.ESSAY: return reverse('essays:detail', kwargs={"slug": self.slug}) - if self.post_type == PostType.RANGE: - m = NewsletterMailing.objects.get(post__id=self.pk) - return reverse('range:range-detail', kwargs={"issue": m.get_issue_str(), "slug": self.slug}) if self.post_type == PostType.SRC: return reverse('src:detail', kwargs={"slug": self.slug}) if self.post_type == PostType.FIELD_NOTE: return reverse('fieldnote:detail', kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) if self.post_type == PostType.GUIDE: - return reverse('guides:guide-detail', kwargs={"topic": str(self.topics.all()[0]).lower(), "slug": self.slug}) + return reverse('guides:guide-post-detail', kwargs={"topic": self.guide_set.all()[0].slug, "slug": self.slug}) if self.post_type == PostType.JRNL: return reverse('jrnl:detail', kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) @@ -264,6 +259,38 @@ class PostModerator(CommentModerator): return True moderator.register(Post, PostModerator) + +class Guide(models.Model): + title = models.CharField(max_length=200) + subtitle = models.CharField(max_length=200, blank=True) + seo_title = models.CharField(max_length=200, blank=True) + slug = models.SlugField() + body_markdown = models.TextField() + body_html = models.TextField(blank=True) + dek = models.TextField(null=True, blank=True) + meta_description = models.CharField(max_length=256, blank=True) + last_updated = models.DateTimeField(auto_now=True) + is_featured = models.BooleanField(blank=True, default=False) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + featured_image = models.ForeignKey(LuxImage, on_delete=models.SET_NULL, null=True, blank=True) + posts = models.ManyToManyField(Post, blank=True) + related = models.ManyToManyField(RelatedPost, blank=True) + + class Meta: + ordering = ('-last_updated',) + get_latest_by = 'last_updated' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse('guides:guide-detail', kwargs={"slug": self.slug}) + + @receiver(comment_was_posted, sender=Comment) def cache_gravatar(sender, comment, **kwargs): gravatar_exists = has_gravatar(comment.email) |