Commits

Anonymous committed 025423b

Added ThreadManager

Comments (0)

Files changed (1)

gnocchi/forum/models.py

 
     def __unicode__(self):
         return u'[%s] %s' % (self.category, self.title,)
+
     @models.permalink
     def get_absolute_url(self):
         return ('forum-detail', (), {
             'forum_id': self.pk
         })
 
+class ThreadManager(models.Model):
+    def annotated(self):
+        return self.get_query_set().annotate(
+            most_recent_post=Max('post__created'),
+            post_count=Count('post'),
+        )
+
 class Thread(models.Model):
     '''List of posts within a Topic'''
     title = models.CharField(max_length=256)
     pinned = models.BooleanField(default=False)
     state = models.CharField(max_length=16, choices=THREAD_STATE_CHOICES)
 
+    objects = ThreadManager()
+
     class Meta:
         ordering = ('-pinned',)
         unique_together = (