當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。