comparison gpp/forums/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 dcc929973bba
children 8fd4984d5c3b
comparison
equal deleted inserted replaced
276:8a46843c258f 277:d424b8bae71d
241 """ 241 """
242 A post is an instance of a user's single contribution to a topic. 242 A post is an instance of a user's single contribution to a topic.
243 """ 243 """
244 topic = models.ForeignKey(Topic, related_name='posts') 244 topic = models.ForeignKey(Topic, related_name='posts')
245 user = models.ForeignKey(User, related_name='posts') 245 user = models.ForeignKey(User, related_name='posts')
246 creation_date = models.DateTimeField(auto_now_add=True) 246 creation_date = models.DateTimeField(db_index=True)
247 update_date = models.DateTimeField(null=True) 247 update_date = models.DateTimeField(db_index=True)
248 body = models.TextField() 248 body = models.TextField()
249 html = models.TextField() 249 html = models.TextField()
250 user_ip = models.IPAddressField(blank=True, default='', null=True) 250 user_ip = models.IPAddressField(blank=True, default='', null=True)
251 251
252 class Meta: 252 class Meta:
267 267
268 def __unicode__(self): 268 def __unicode__(self):
269 return self.summary() 269 return self.summary()
270 270
271 def save(self, *args, **kwargs): 271 def save(self, *args, **kwargs):
272 if not self.id:
273 self.creation_date = datetime.datetime.now()
274 self.update_date = self.creation_date
275
272 self.html = site_markup(self.body) 276 self.html = site_markup(self.body)
273 super(Post, self).save(*args, **kwargs) 277 super(Post, self).save(*args, **kwargs)
274 278
275 def delete(self, *args, **kwargs): 279 def delete(self, *args, **kwargs):
276 first_post_id = self.topic.posts.all()[0].id 280 first_post_id = self.topic.posts.all()[0].id
277 super(Post, self).delete(*args, **kwargs) 281 super(Post, self).delete(*args, **kwargs)
278 if self.id == first_post_id: 282 if self.id == first_post_id:
279 self.topic.delete() 283 self.topic.delete()
280 284
281 def has_been_edited(self): 285 def has_been_edited(self):
282 return self.update_date is not None 286 return self.update_date > self.creation_date
283 287
284 def touch(self): 288 def touch(self):
285 """Call this function to indicate the post has been edited.""" 289 """Call this function to indicate the post has been edited."""
286 self.update_date = datetime.datetime.now() 290 self.update_date = datetime.datetime.now()
287 291