Show More
@@ -1,5 +1,5 b'' | |||
|
1 | 1 | import logging |
|
2 | from django.db.models import Count | |
|
2 | from django.db.models import Count, Sum | |
|
3 | 3 | from django.utils import timezone |
|
4 | 4 | from django.core.cache import cache |
|
5 | 5 | from django.db import models |
@@ -81,12 +81,8 b' class Thread(models.Model):' | |||
|
81 | 81 | return self.replies.count() |
|
82 | 82 | |
|
83 | 83 | def get_images_count(self): |
|
84 | # TODO Use sum | |
|
85 | total_count = 0 | |
|
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 | |
|
84 | return self.replies.annotate(images_count=Count( | |
|
85 | 'images')).aggregate(Sum('images_count'))['images_count__sum'] | |
|
90 | 86 | |
|
91 | 87 | def can_bump(self): |
|
92 | 88 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now