comparison gpp/forums/models.py @ 83:5b4c812b448e

Forums: Added the ability to add a new topic. This is very much a work in progress.
author Brian Neal <bgneal@gmail.com>
date Sat, 29 Aug 2009 20:54:16 +0000
parents bc3978f023c2
children 62af8cd8f57b
comparison
equal deleted inserted replaced
82:bc3978f023c2 83:5b4c812b448e
97 self.update_date = self.last_post.creation_date 97 self.update_date = self.last_post.creation_date
98 else: 98 else:
99 self.last_post = None 99 self.last_post = None
100 self.update_date = self.creation_date 100 self.update_date = self.creation_date
101 101
102 def reply_count(self):
103 """
104 Returns the number of replies to a topic. The first post
105 doesn't count as a reply.
106 """
107 if self.post_count > 1:
108 return self.post_count - 1
109 return 0
110
102 111
103 class Post(models.Model): 112 class Post(models.Model):
104 topic = models.ForeignKey(Topic, related_name='posts') 113 topic = models.ForeignKey(Topic, related_name='posts')
105 user = models.ForeignKey(User, related_name='posts') 114 user = models.ForeignKey(User, related_name='posts')
106 creation_date = models.DateTimeField(auto_now_add=True) 115 creation_date = models.DateTimeField(auto_now_add=True)
107 update_date = models.DateTimeField(auto_now=True) 116 update_date = models.DateTimeField(auto_now=True)
108 body = models.TextField() 117 body = models.TextField()
109 html = models.TextField() 118 html = models.TextField()
110 user_ip = models.IPAddressField(blank=True, default='') 119 user_ip = models.IPAddressField(blank=True, default='', null=True)
111 120
112 class Meta: 121 class Meta:
113 ordering = ('creation_date', ) 122 ordering = ('creation_date', )
114 123
115 def summary(self): 124 def summary(self):