本文整理匯總了Python中django.db.models.expressions.Value._as_sql方法的典型用法代碼示例。如果您正苦於以下問題:Python Value._as_sql方法的具體用法?Python Value._as_sql怎麽用?Python Value._as_sql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.models.expressions.Value
的用法示例。
在下文中一共展示了Value._as_sql方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: process_rhs
# 需要導入模塊: from django.db.models.expressions import Value [as 別名]
# 或者: from django.db.models.expressions.Value import _as_sql [as 別名]
def process_rhs(self, compiler, connection):
value = self.rhs
if self.bilateral_transforms:
if self.rhs_is_direct_value():
# Do not call get_db_prep_lookup here as the value will be
# transformed before being used for lookup
value = Value(value, output_field=self.lhs.output_field)
value = self.apply_bilateral_transforms(value)
value = value.resolve_expression(compiler.query)
# Due to historical reasons there are a couple of different
# ways to produce sql here. get_compiler is likely a Query
# instance, _as_sql QuerySet and as_sql just something with
# as_sql. Finally the value can of course be just plain
# Python value.
if hasattr(value, 'get_compiler'):
value = value.get_compiler(connection=connection)
if hasattr(value, 'as_sql'):
sql, params = compiler.compile(value)
return '(' + sql + ')', params
if hasattr(value, '_as_sql'):
sql, params = value._as_sql(connection=connection)
return '(' + sql + ')', params
else:
return self.get_db_prep_lookup(value, connection)
示例2:
# 需要導入模塊: from django.db.models.expressions import Value [as 別名]
# 或者: from django.db.models.expressions.Value import _as_sql [as 別名]
from copy import copy