本文整理匯總了Python中django.db.models.sql.query.Query.add_extra方法的典型用法代碼示例。如果您正苦於以下問題:Python Query.add_extra方法的具體用法?Python Query.add_extra怎麽用?Python Query.add_extra使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.models.sql.query.Query
的用法示例。
在下文中一共展示了Query.add_extra方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_related_where
# 需要導入模塊: from django.db.models.sql.query import Query [as 別名]
# 或者: from django.db.models.sql.query.Query import add_extra [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
示例2: get_related_decrement_value
# 需要導入模塊: from django.db.models.sql.query import Query [as 別名]
# 或者: from django.db.models.sql.query.Query import add_extra [as 別名]
def get_related_decrement_value(self, using):
qn = self.get_quote_name(using)
related_query = Query(self.manager.related.model)
related_query.add_extra(None, None,
["%s = %s.%s" % (qn(self.model._meta.pk.get_attname_column()[1]), 'OLD', qn(self.manager.related.field.m2m_column_name()))],
None, None, None)
related_query.add_fields([self.fieldname])
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()
return "%s - (%s)" % (qn(self.fieldname), related_filter_where)