本文整理匯總了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
示例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
示例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)
示例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]
示例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)
# 返回活躍的友情鏈接查詢集
示例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)
示例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
示例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
示例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]
示例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,
}
示例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,
}
示例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']
示例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']
示例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)
示例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)