Mercurial > public > sg101
diff news/models.py @ 1001:c6c3ba5cf6eb
V2 news stories use forums for comments.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 Nov 2015 00:27:42 -0600 |
parents | abd4c02aefdb |
children | 28d68f97cb26 |
line wrap: on
line diff
--- a/news/models.py Tue Nov 24 22:55:18 2015 -0600 +++ b/news/models.py Thu Nov 26 00:27:42 2015 -0600 @@ -19,6 +19,13 @@ title = models.CharField(max_length=64) slug = models.SlugField(max_length=64) icon = models.ImageField(upload_to='news/categories/', blank=True) + forum_slug = models.CharField( + max_length=80, + default='', + blank=True, + help_text=("Identifies the forum to create comment threads in for " + "stories in this category. If blank, no comment threads " + "will be created for stories in this category.")) def __unicode__(self): return self.title @@ -85,6 +92,10 @@ class Story(StoryBase): """Model for news stories""" + forums_topic = models.OneToOneField('forums.Topic', blank=True, null=True, + on_delete=models.SET_NULL, + db_index=False, + help_text="Forum topic used for comments") @models.permalink def get_absolute_url(self): @@ -99,10 +110,17 @@ verbose_name_plural = 'news stories' def can_comment_on(self): + # Only used for version 0 stories now = datetime.datetime.now() delta = now - self.date_submitted return self.allow_comments and delta.days < 30 + def forums_comment_count(self): + """Returns number of comments for V2 news stories.""" + if self.forums_topic: + return max(0, self.forums_topic.post_count - 1) + return 0 + def search_title(self): return self.title