X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/4c0a2cdc4ea9531a47943ececfa3dc656a0462f1..3726f9b225fb5c39cbf067f53d4cf6f7d8a9f326:/apps/catalogue/models/tag.py diff --git a/apps/catalogue/models/tag.py b/apps/catalogue/models/tag.py index 1309cbbd2..7280060a6 100644 --- a/apps/catalogue/models/tag.py +++ b/apps/catalogue/models/tag.py @@ -20,6 +20,7 @@ TAG_CATEGORIES = ( ('theme', _('theme')), ('set', _('set')), ('book', _('book')), + ('thing', _('thing')), # things shown on pictures ) @@ -37,6 +38,7 @@ class Tag(TagBase): user = models.ForeignKey(User, blank=True, null=True) book_count = models.IntegerField(_('book count'), blank=True, null=True) + picture_count = models.IntegerField(_('picture count'), blank=True, null=True) gazeta_link = models.CharField(blank=True, max_length=240) wiki_link = models.CharField(blank=True, max_length=240) @@ -53,6 +55,7 @@ class Tag(TagBase): 'gatunek': 'genre', 'motyw': 'theme', 'polka': 'set', + 'obiekt': 'thing', } categories_dict = dict((item[::-1] for item in categories_rev.iteritems())) @@ -109,6 +112,22 @@ class Tag(TagBase): 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() + @staticmethod def get_tag_list(tags): if isinstance(tags, basestring):