Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
1000:abd4c02aefdb | 1001:c6c3ba5cf6eb |
---|---|
17 class Category(models.Model): | 17 class Category(models.Model): |
18 """News stories belong to categories""" | 18 """News stories belong to categories""" |
19 title = models.CharField(max_length=64) | 19 title = models.CharField(max_length=64) |
20 slug = models.SlugField(max_length=64) | 20 slug = models.SlugField(max_length=64) |
21 icon = models.ImageField(upload_to='news/categories/', blank=True) | 21 icon = models.ImageField(upload_to='news/categories/', blank=True) |
22 forum_slug = models.CharField( | |
23 max_length=80, | |
24 default='', | |
25 blank=True, | |
26 help_text=("Identifies the forum to create comment threads in for " | |
27 "stories in this category. If blank, no comment threads " | |
28 "will be created for stories in this category.")) | |
22 | 29 |
23 def __unicode__(self): | 30 def __unicode__(self): |
24 return self.title | 31 return self.title |
25 | 32 |
26 def num_stories(self): | 33 def num_stories(self): |
83 verbose_name_plural = 'Pending Stories' | 90 verbose_name_plural = 'Pending Stories' |
84 | 91 |
85 | 92 |
86 class Story(StoryBase): | 93 class Story(StoryBase): |
87 """Model for news stories""" | 94 """Model for news stories""" |
95 forums_topic = models.OneToOneField('forums.Topic', blank=True, null=True, | |
96 on_delete=models.SET_NULL, | |
97 db_index=False, | |
98 help_text="Forum topic used for comments") | |
88 | 99 |
89 @models.permalink | 100 @models.permalink |
90 def get_absolute_url(self): | 101 def get_absolute_url(self): |
91 return ('news.views.story', [str(self.id)]) | 102 return ('news.views.story', [str(self.id)]) |
92 | 103 |
97 ordering = ['-date_submitted'] | 108 ordering = ['-date_submitted'] |
98 verbose_name = 'news story' | 109 verbose_name = 'news story' |
99 verbose_name_plural = 'news stories' | 110 verbose_name_plural = 'news stories' |
100 | 111 |
101 def can_comment_on(self): | 112 def can_comment_on(self): |
113 # Only used for version 0 stories | |
102 now = datetime.datetime.now() | 114 now = datetime.datetime.now() |
103 delta = now - self.date_submitted | 115 delta = now - self.date_submitted |
104 return self.allow_comments and delta.days < 30 | 116 return self.allow_comments and delta.days < 30 |
117 | |
118 def forums_comment_count(self): | |
119 """Returns number of comments for V2 news stories.""" | |
120 if self.forums_topic: | |
121 return max(0, self.forums_topic.post_count - 1) | |
122 return 0 | |
105 | 123 |
106 def search_title(self): | 124 def search_title(self): |
107 return self.title | 125 return self.title |
108 | 126 |
109 def search_summary(self): | 127 def search_summary(self): |