Commits

funkybob  committed a0117eb

Added post_count property to Thread
made post_count and last_post cached

  • Participants
  • Parent commits 1629ada

Comments (0)

Files changed (1)

File gnocchi_forum/models.py

 from django.db import models
 from datetime import datetime
 
+from gnocchi_forum.utils import CachedProperty
+
 THREAD_STATE_CHOICES = (
     ('open', 'Open to General postings.'),
     ('frozen', 'No new posts allowed.'),
             'thread_id': self.id,
         }
 
+    @CachedProperty
+    def post_count(self):
+        return self.post_set.aggregate(
+            post_count=models.Count('id')
+        )['post_count']
+
+    @CachedProperty
     def last_post(self):
         try:
             return self.post_set.order_by('-created')[0]