# HG changeset patch # User ymh # Date 1495559445 -7200 # Node ID 7f3fdcba790281056540523a31d5e2faa19d6c28 # Parent a051b60f4b265f5fb2a939d1345fa3568779a977 more natural way to count total item in django diff -r a051b60f4b26 -r 7f3fdcba7902 src/iconolab/models.py --- a/src/iconolab/models.py Tue May 23 16:49:39 2017 +0200 +++ b/src/iconolab/models.py Tue May 23 19:10:45 2017 +0200 @@ -54,12 +54,16 @@ show_image_on_home = models.BooleanField(default=False) @cached_property + def items_count(self): + return self.items.count() + + @cached_property def completed_percent(self): items_with_annotation = \ ImageStats.objects.filter(image__item__collection = self, annotations_count__gt=0)\ .values('image__item').distinct().count() - total_items = Item.objects.filter(collection=self).count() + total_items = self.items_count return int(round((items_with_annotation * 100) / total_items))