comparison gpp/news/models.py @ 277:d424b8bae71d

Fixing #128 and #129. Add elsewhere weblinks to search content. Add support for haystack's get_update_field() method.
author Brian Neal <bgneal@gmail.com>
date Sat, 02 Oct 2010 23:24:39 +0000
parents 1246a4f1ab4f
children 53fdaf0da539
comparison
equal deleted inserted replaced
276:8a46843c258f 277:d424b8bae71d
34 long_text = models.TextField(blank=True) 34 long_text = models.TextField(blank=True)
35 date_submitted = models.DateTimeField(db_index=True) 35 date_submitted = models.DateTimeField(db_index=True)
36 allow_comments = models.BooleanField(default=True) 36 allow_comments = models.BooleanField(default=True)
37 tags = TagField() 37 tags = TagField()
38 front_page_expiration = models.DateField(null=True, blank=True) 38 front_page_expiration = models.DateField(null=True, blank=True)
39 update_date = models.DateTimeField(db_index=True, blank=True)
39 40
40 class Meta: 41 class Meta:
41 abstract = True 42 abstract = True
42 43
43 44
44 class PendingStory(StoryBase): 45 class PendingStory(StoryBase):
45 """Stories submitted by users are held pending admin approval""" 46 """Stories submitted by users are held pending admin approval"""
46 47
47 def save(self, *args, **kwargs): 48 def save(self, *args, **kwargs):
48 if not self.pk: 49 if not self.pk:
49 self.date_submitted = datetime.datetime.now() 50 if not self.date_submitted:
51 self.date_submitted = datetime.datetime.now()
52 self.update_date = self.date_submitted
53 else:
54 self.update_date = datetime.datetime.now()
50 55
51 super(PendingStory, self).save(*args, **kwargs) 56 super(PendingStory, self).save(*args, **kwargs)
52 57
53 def __unicode__(self): 58 def __unicode__(self):
54 return self.title 59 return self.title
71 class Meta: 76 class Meta:
72 ordering = ('-date_submitted', ) 77 ordering = ('-date_submitted', )
73 verbose_name = 'news story' 78 verbose_name = 'news story'
74 verbose_name_plural = 'news stories' 79 verbose_name_plural = 'news stories'
75 80
81 def save(self, *args, **kwargs):
82 if not self.pk:
83 self.date_submitted = datetime.datetime.now()
84 self.update_date = self.date_submitted
85 else:
86 self.update_date = datetime.datetime.now()
87
88 super(Story, self).save(*args, **kwargs)
89
76 def can_comment_on(self): 90 def can_comment_on(self):
77 now = datetime.datetime.now() 91 now = datetime.datetime.now()
78 delta = now - self.date_submitted 92 delta = now - self.date_submitted
79 return self.allow_comments and delta.days < 30 93 return self.allow_comments and delta.days < 30
80 94