- """ returns global book count for book tags, fragment count for themes """
-
- if self.book_count is None:
- if self.category == 'book':
- # never used
- objects = Book.objects.none()
- elif self.category == 'theme':
- objects = Fragment.tagged.with_all((self,))
- else:
- objects = Book.tagged.with_all((self,)).order_by()
- if self.category != 'set':
- # eliminate descendants
- l_tags = Tag.objects.filter(slug__in=[book.book_tag_slug() for book in objects])
- descendants_keys = [book.pk for book in Book.tagged.with_any(l_tags)]
- if descendants_keys:
- objects = objects.exclude(pk__in=descendants_keys)
- self.book_count = objects.count()
- self.save()
- return self.book_count
+ """Returns global book count for book tags, fragment count for themes."""
+
+ if self.category == 'book':
+ # never used
+ objects = Book.objects.none()
+ elif self.category == 'theme':
+ objects = Fragment.tagged.with_all((self,))
+ else:
+ objects = Book.tagged.with_all((self,)).order_by()
+ if self.category != 'set':
+ # eliminate descendants
+ l_tags = Tag.objects.filter(slug__in=[book.book_tag_slug() for book in objects])
+ descendants_keys = [book.pk for book in Book.tagged.with_any(l_tags)]
+ if descendants_keys:
+ objects = objects.exclude(pk__in=descendants_keys)
+ return objects.count()