comparison gpp/forums/models.py @ 115:0ce0104c7df3

Forums: split topic.
author Brian Neal <bgneal@gmail.com>
date Thu, 22 Oct 2009 02:57:18 +0000
parents d97ceb95ce02
children 19b64e8f02a2
comparison
equal deleted inserted replaced
114:535d02d1c017 115:0ce0104c7df3
226 A post is an instance of a user's single contribution to a topic. 226 A post is an instance of a user's single contribution to a topic.
227 """ 227 """
228 topic = models.ForeignKey(Topic, related_name='posts') 228 topic = models.ForeignKey(Topic, related_name='posts')
229 user = models.ForeignKey(User, related_name='posts') 229 user = models.ForeignKey(User, related_name='posts')
230 creation_date = models.DateTimeField(auto_now_add=True) 230 creation_date = models.DateTimeField(auto_now_add=True)
231 update_date = models.DateTimeField(auto_now=True) 231 update_date = models.DateTimeField(null=True)
232 body = models.TextField() 232 body = models.TextField()
233 html = models.TextField() 233 html = models.TextField()
234 user_ip = models.IPAddressField(blank=True, default='', null=True) 234 user_ip = models.IPAddressField(blank=True, default='', null=True)
235 235
236 class Meta: 236 class Meta:
260 super(Post, self).delete(*args, **kwargs) 260 super(Post, self).delete(*args, **kwargs)
261 if self.id == first_post_id: 261 if self.id == first_post_id:
262 self.topic.delete() 262 self.topic.delete()
263 263
264 def has_been_edited(self): 264 def has_been_edited(self):
265 return (self.update_date - self.creation_date) > POST_EDIT_DELTA 265 return self.update_date is not None
266
267 def touch(self):
268 """Call this function to indicate the post has been edited."""
269 self.update_date = datetime.datetime.now()
266 270
267 271
268 class FlaggedPost(models.Model): 272 class FlaggedPost(models.Model):
269 """This model represents a user flagging a post as inappropriate.""" 273 """This model represents a user flagging a post as inappropriate."""
270 user = models.ForeignKey(User) 274 user = models.ForeignKey(User)
325 def __unicode__(self): 329 def __unicode__(self):
326 return u'Topic: %d User: %d Date: %s' % (self.topic.id, self.user.id, 330 return u'Topic: %d User: %d Date: %s' % (self.topic.id, self.user.id,
327 self.last_visit.strftime('%Y-%m-%d %H:%M:%S')) 331 self.last_visit.strftime('%Y-%m-%d %H:%M:%S'))
328 332
329 def save(self, *args, **kwargs): 333 def save(self, *args, **kwargs):
330 if self.id is None: 334 if self.id is one:
331 self.touch() 335 self.touch()
332 super(TopicLastVisit, self).save(*args, **kwargs) 336 super(TopicLastVisit, self).save(*args, **kwargs)
333 337
334 def touch(self): 338 def touch(self):
335 self.last_visit = datetime.datetime.now() 339 self.last_visit = datetime.datetime.now()