##// END OF EJS Templates
Use aggregation to get the thread images count
neko259 -
r891:72a58333 default
parent child Browse files
Show More
@@ -1,5 +1,5 b''
1 import logging
1 import logging
2 from django.db.models import Count
2 from django.db.models import Count, Sum
3 from django.utils import timezone
3 from django.utils import timezone
4 from django.core.cache import cache
4 from django.core.cache import cache
5 from django.db import models
5 from django.db import models
@@ -81,12 +81,8 b' class Thread(models.Model):'
81 return self.replies.count()
81 return self.replies.count()
82
82
83 def get_images_count(self):
83 def get_images_count(self):
84 # TODO Use sum
84 return self.replies.annotate(images_count=Count(
85 total_count = 0
85 'images')).aggregate(Sum('images_count'))['images_count__sum']
86 for post_with_image in self.replies.annotate(images_count=Count(
87 'images')):
88 total_count += post_with_image.images_count
89 return total_count
90
86
91 def can_bump(self):
87 def can_bump(self):
92 """
88 """
General Comments 0
You need to be logged in to leave comments. Login now