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


Python aggregates.Count方法代码示例

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


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

示例1: get_count

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_count(self, using):
        """
        Performs a COUNT() query using the current filter constraints.
        """
        obj = self.clone()
        obj.add_annotation(Count('*'), alias='__count', is_summary=True)
        number = obj.get_aggregation(using, ['__count'])['__count']
        if number is None:
            number = 0
        return number 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:query.py

示例2: get_count

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_count(self, using):
        """
        Perform a COUNT() query using the current filter constraints.
        """
        obj = self.clone()
        obj.add_annotation(Count('*'), alias='__count', is_summary=True)
        number = obj.get_aggregation(using, ['__count'])['__count']
        if number is None:
            number = 0
        return number 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:12,代码来源:query.py

示例3: all_hot_dicussions

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def all_hot_dicussions(request):
    discussions = Discuss.objects.annotate(reply_num=Count('replys')).all()[:10]
    discussions = sorted(discussions, key=lambda x: x.reply_num, reverse=True)

    context = {
        'discussions': discussions,
    }
    return render(request, 'Discussion/hot_discussions.html', context=context) 
开发者ID:Arianxx,项目名称:BookForum,代码行数:10,代码来源:views.py

示例4: get_hot_discussions

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_hot_discussions(num=5):
    """
    得到指定数量的热门讨论

    :param num: 想要得到的讨论数量
    :return: Discuss模型的实例列表
    """
    discussions = Discuss.objects.annotate(reply_num=Count('replys')).all()
    discussions = sorted(discussions, key=lambda x: x.reply_num, reverse=True)
    return discussions[:num] 
开发者ID:Arianxx,项目名称:BookForum,代码行数:12,代码来源:discussion_tags.py

示例5: get_tag_list

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_tag_list():
    """返回标签列表"""
    return Tag.objects.annotate(total_num=Count('article')).filter(total_num__gt=0)


# 返回活跃的友情链接查询集 
开发者ID:stormsha,项目名称:blog,代码行数:8,代码来源:blog_tags.py

示例6: items

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def items(self):
        return Category.objects.annotate(total_num=Count('article')).filter(total_num__gt=0) 
开发者ID:stormsha,项目名称:blog,代码行数:4,代码来源:sitemaps.py

示例7: get_category

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_category():
    category_list = Category.objects.annotate(post_num=Count('post')).order_by('-post_num')
    Category.objects.values()
    return category_list 
开发者ID:r26zhao,项目名称:django_blog,代码行数:6,代码来源:blog_tags.py

示例8: get_tag

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_tag():
    tag_list = Tag.objects.annotate(post_num=Count('post')).order_by('-post_num')
    return tag_list 
开发者ID:r26zhao,项目名称:django_blog,代码行数:5,代码来源:blog_tags.py

示例9: get_comment_rank

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_comment_rank(num=5):
    app_model = settings.COMMENT_ENTRY_MODEL.split('.')
    Post = apps.get_model(*app_model)
    post_list = Post.objects.annotate(comment_num=Count('comment')).order_by('-comment_num')
    return post_list[:num] 
开发者ID:r26zhao,项目名称:django_blog,代码行数:7,代码来源:comment_tags.py

示例10: show_categories

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def show_categories(context):
    category_list = Category.objects.annotate(num_posts=Count('post')).filter(num_posts__gt=0)
    return {
        'category_list': category_list,
    } 
开发者ID:HelloGitHub-Team,项目名称:HelloDjango-blog-tutorial,代码行数:7,代码来源:blog_extras.py

示例11: show_tags

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def show_tags(context):
    tag_list = Tag.objects.annotate(num_posts=Count('post')).filter(num_posts__gt=0)
    return {
        'tag_list': tag_list,
    } 
开发者ID:HelloGitHub-Team,项目名称:HelloDjango-blog-tutorial,代码行数:7,代码来源:blog_extras.py

示例12: _get_points_earned_trials_count

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def _get_points_earned_trials_count(self):
        """Get points earned and trials count from the sequence.

        :return tuple([trials_count, points_earned])
        """
        items_result = self.sequence.items.aggregate(
            points_earned=Sum('score'), trials_count=Count('score')
        )
        return items_result['trials_count'], items_result['points_earned'] 
开发者ID:harvard-vpal,项目名称:bridge-adaptivity,代码行数:11,代码来源:base.py

示例13: _get_points_earned_trials_count

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def _get_points_earned_trials_count(self):
        """Get points earned and trials count from the sequence.

        :return tuple([trials_count, points_earned])
        """
        # Note(idegtiarov) With the first non-problem activity in the sequence and default value of the threshold
        # item_result returns None, 0 which are not appropriate for the grade calculation method, valid default values
        # are provided to fix this issue.
        items_result = self.sequence.items.exclude(is_problem=False).aggregate(
            points_earned=Coalesce(Sum('score'), 0), trials_count=Greatest(Count('score'), 1)
        )
        return items_result['trials_count'], items_result['points_earned'] 
开发者ID:harvard-vpal,项目名称:bridge-adaptivity,代码行数:14,代码来源:policy_points_earned.py

示例14: get_toolcates

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_toolcates():
    '''获取所有工具分类,只显示有工具的分类'''
    return ToolCategory.objects.annotate(total_num=Count('toollink')).filter(total_num__gt=0) 
开发者ID:Hopetree,项目名称:izone,代码行数:5,代码来源:tool_tags.py

示例15: get_tag_list

# 需要导入模块: from django.db.models import aggregates [as 别名]
# 或者: from django.db.models.aggregates import Count [as 别名]
def get_tag_list():
    '''返回标签列表'''
    return Tag.objects.annotate(total_num=Count('article')).filter(total_num__gt=0) 
开发者ID:Hopetree,项目名称:izone,代码行数:5,代码来源:blog_tags.py


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