本文整理汇总了Python中django.db.models.sql.query.Query.add_count_column方法的典型用法代码示例。如果您正苦于以下问题:Python Query.add_count_column方法的具体用法?Python Query.add_count_column怎么用?Python Query.add_count_column使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.sql.query.Query
的用法示例。
在下文中一共展示了Query.add_count_column方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_related_where
# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import add_count_column [as 别名]
def get_related_where(self, fk_name, using, type):
qn = self.get_quote_name(using)
related_where = ["%s = %s.%s" % (qn(self.model._meta.pk.get_attname_column()[1]), type, qn(fk_name))]
related_query = Query(self.manager.related.model)
for name, value in self.filter.iteritems():
related_query.add_q(Q(**{name: value}))
for name, value in self.exclude.iteritems():
related_query.add_q(~Q(**{name: value}))
related_query.add_extra(
None,
None,
[
"%s = %s.%s"
% (
qn(self.model._meta.pk.get_attname_column()[1]),
type,
qn(self.manager.related.field.m2m_column_name()),
)
],
None,
None,
None,
)
related_query.add_count_column()
related_query.clear_ordering(force_empty=True)
related_query.default_cols = False
related_filter_where, related_where_params = related_query.get_compiler(using=using).as_sql()
if related_filter_where is not None:
related_where.append("(" + related_filter_where + ") > 0")
return related_where, related_where_params