当前位置: 首页>>代码示例>>Python>>正文


Python TaggedItem.bulk_lookup_kwargs方法代码示例

本文整理汇总了Python中taggit.models.TaggedItem.bulk_lookup_kwargs方法的典型用法代码示例。如果您正苦于以下问题:Python TaggedItem.bulk_lookup_kwargs方法的具体用法?Python TaggedItem.bulk_lookup_kwargs怎么用?Python TaggedItem.bulk_lookup_kwargs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在taggit.models.TaggedItem的用法示例。


在下文中一共展示了TaggedItem.bulk_lookup_kwargs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_tag_cloud

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import bulk_lookup_kwargs [as 别名]
def get_tag_cloud(model, queryset, tags_filter=None):
    if tags_filter is None:
        tags_filter = set()
        for item in queryset.all():
            tags_filter.update(item.tags.all())

    tags_filter = set([tag.id for tag in tags_filter])
    tags = set(TaggedItem.objects.filter(
        content_type__model=model.__name__.lower()
    ).values_list('tag_id', flat=True))

    if tags_filter is not None:
        tags = tags.intersection(tags_filter)
    tag_ids = list(tags)

    kwargs = TaggedItem.bulk_lookup_kwargs(queryset)
    kwargs['tag_id__in'] = tag_ids
    counted_tags = dict(TaggedItem.objects
                                  .filter(**kwargs)
                                  .values('tag')
                                  .annotate(count=models.Count('tag'))
                                  .values_list('tag', 'count'))
    tags = TaggedItem.tag_model().objects.filter(pk__in=counted_tags.keys())
    for tag in tags:
        tag.count = counted_tags[tag.pk]
    return sorted(tags, key=lambda x: -x.count)
开发者ID:okfish,项目名称:django-oscar-news,代码行数:28,代码来源:models.py

示例2: get_tags

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import bulk_lookup_kwargs [as 别名]
    def get_tags(self, entries=None, language=None):
        """Returns tags used to tag post and its count. Results are ordered by count."""

        if not entries:
            entries = self

        if language:
            entries = entries.filter_by_language(language)
        entries = entries.distinct()
        if not entries:
            return []
        kwargs = TaggedItem.bulk_lookup_kwargs(entries)

        # aggregate and sort
        counted_tags = dict(TaggedItem.objects
                                      .filter(**kwargs)
                                      .values('tag')
                                      .annotate(count=models.Count('tag'))
                                      .values_list('tag', 'count'))

        # and finally get the results
        tags = Tag.objects.filter(pk__in=counted_tags.keys())
        for tag in tags:
            tag.count = counted_tags[tag.pk]
        return sorted(tags, key=lambda x: -x.count)
开发者ID:francofuji,项目名称:aldryn-blog,代码行数:27,代码来源:models.py

示例3: get_tags

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import bulk_lookup_kwargs [as 别名]
    def get_tags(self, request, namespace):
        """
        Get tags with articles count for given namespace string.

        Return list of Tag objects ordered by custom 'num_articles' attribute.
        """
        if (request and hasattr(request, 'toolbar') and
                request.toolbar and request.toolbar.edit_mode):
            articles = self.namespace(namespace)
        else:
            articles = self.published().namespace(namespace)
        if not articles:
            # return empty iterable early not to perform useless requests
            return []
        kwargs = TaggedItem.bulk_lookup_kwargs(articles)

        # aggregate and sort
        counted_tags = dict(TaggedItem.objects
                            .filter(**kwargs)
                            .values('tag')
                            .annotate(tag_count=models.Count('tag'))
                            .values_list('tag', 'tag_count'))

        # and finally get the results
        tags = Tag.objects.filter(pk__in=counted_tags.keys())
        for tag in tags:
            tag.num_articles = counted_tags[tag.pk]
        return sorted(tags, key=attrgetter('num_articles'), reverse=True)
开发者ID:stefanfoulis,项目名称:aldryn-newsblog,代码行数:30,代码来源:managers.py

示例4: tag_cloud

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import bulk_lookup_kwargs [as 别名]
 def tag_cloud(self, other_model=None, queryset=None, published=True):
     from taggit.models import TaggedItem
     tag_ids = self._taglist(other_model, queryset)
     kwargs = {}
     if published:
         kwargs = TaggedItem.bulk_lookup_kwargs(self.model.objects.published())
     kwargs['tag_id__in'] = tag_ids
     counted_tags = dict(TaggedItem.objects
                                   .filter(**kwargs)
                                   .values('tag')
                                   .annotate(count=models.Count('tag'))
                                   .values_list('tag', 'count'))
     tags = TaggedItem.tag_model().objects.filter(pk__in=counted_tags.keys())
     for tag in tags:
         tag.count = counted_tags[tag.pk]
     return sorted(tags, key=lambda x: -x.count)
开发者ID:aleks-sngn,项目名称:djangocms-blog,代码行数:18,代码来源:managers.py


注:本文中的taggit.models.TaggedItem.bulk_lookup_kwargs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。