- def get_count(self):
- """Returns global book count for book tags, fragment count for themes."""
- from catalogue.models import Book, Fragment
-
- 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.iterator()])
- descendants_keys = [book.pk for book in Book.tagged.with_any(l_tags).iterator()]
- if descendants_keys:
- objects = objects.exclude(pk__in=descendants_keys)
- return objects.count()
-
- # I shouldn't break the get_count() api
- # just to include pictures.
- def get_picture_count(self):
- from picture.models import Picture
-
- if self.category == 'book':
- # never used
- objects = Book.objects.none()
- elif self.category == 'theme':
- objects = Picture.tagged.with_all((self,))
- elif self.category == 'thing':
- objects = Picture.tagged.with_all((self,))
- else:
- objects = Picture.tagged.with_all((self,)).order_by()
- return objects.count()
-