当前位置: 首页>>代码示例>>Python>>正文


Python Query.build_where方法代码示例

本文整理汇总了Python中django.db.models.sql.query.Query.build_where方法的典型用法代码示例。如果您正苦于以下问题:Python Query.build_where方法的具体用法?Python Query.build_where怎么用?Python Query.build_where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.sql.query.Query的用法示例。


在下文中一共展示了Query.build_where方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_simple_query

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def test_simple_query(self):
     query = Query(Author)
     where = query.build_where(Q(num__gt=2))
     lookup = where.children[0]
     self.assertIsInstance(lookup, GreaterThan)
     self.assertEqual(lookup.rhs, 2)
     self.assertEqual(lookup.lhs.target, Author._meta.get_field('num'))
开发者ID:EmadMokhtar,项目名称:django,代码行数:9,代码来源:test_query.py

示例2: _get_condition_sql

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def _get_condition_sql(self, model, schema_editor):
     if self.condition is None:
         return None
     query = Query(model=model)
     where = query.build_where(self.condition)
     compiler = query.get_compiler(connection=schema_editor.connection)
     sql, params = where.as_sql(compiler, schema_editor.connection)
     return sql % tuple(schema_editor.quote_value(p) for p in params)
开发者ID:EmadMokhtar,项目名称:django,代码行数:10,代码来源:constraints.py

示例3: constraint_sql

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def constraint_sql(self, model, schema_editor):
     query = Query(model)
     where = query.build_where(self.check)
     connection = schema_editor.connection
     compiler = connection.ops.compiler('SQLCompiler')(query, connection, 'default')
     sql, params = where.as_sql(compiler, connection)
     params = tuple(schema_editor.quote_value(p) for p in params)
     return schema_editor.sql_check_constraint % {'check': sql % params}
开发者ID:RaphaelKimmig,项目名称:django,代码行数:10,代码来源:constraints.py

示例4: test_transform

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def test_transform(self):
     query = Query(Author)
     with register_lookup(CharField, Lower):
         where = query.build_where(~Q(name__lower='foo'))
     lookup = where.children[0]
     self.assertIsInstance(lookup, Exact)
     self.assertIsInstance(lookup.lhs, Lower)
     self.assertIsInstance(lookup.lhs.lhs, SimpleCol)
     self.assertEqual(lookup.lhs.lhs.target, Author._meta.get_field('name'))
开发者ID:EmadMokhtar,项目名称:django,代码行数:11,代码来源:test_query.py

示例5: test_multiple_fields

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def test_multiple_fields(self):
     query = Query(Item)
     where = query.build_where(Q(modified__gt=F('created')))
     lookup = where.children[0]
     self.assertIsInstance(lookup, GreaterThan)
     self.assertIsInstance(lookup.rhs, SimpleCol)
     self.assertIsInstance(lookup.lhs, SimpleCol)
     self.assertEqual(lookup.rhs.target, Item._meta.get_field('created'))
     self.assertEqual(lookup.lhs.target, Item._meta.get_field('modified'))
开发者ID:EmadMokhtar,项目名称:django,代码行数:11,代码来源:test_query.py

示例6: test_negated_nullable

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def test_negated_nullable(self):
     query = Query(Item)
     where = query.build_where(~Q(modified__lt=datetime(2017, 1, 1)))
     self.assertTrue(where.negated)
     lookup = where.children[0]
     self.assertIsInstance(lookup, LessThan)
     self.assertEqual(lookup.lhs.target, Item._meta.get_field('modified'))
     lookup = where.children[1]
     self.assertIsInstance(lookup, IsNull)
     self.assertEqual(lookup.lhs.target, Item._meta.get_field('modified'))
开发者ID:EmadMokhtar,项目名称:django,代码行数:12,代码来源:test_query.py

示例7: test_foreign_key_exclusive

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def test_foreign_key_exclusive(self):
     query = Query(ObjectC)
     where = query.build_where(Q(objecta=None) | Q(objectb=None))
     a_isnull = where.children[0]
     self.assertIsInstance(a_isnull, RelatedIsNull)
     self.assertIsInstance(a_isnull.lhs, SimpleCol)
     self.assertEqual(a_isnull.lhs.target, ObjectC._meta.get_field('objecta'))
     b_isnull = where.children[1]
     self.assertIsInstance(b_isnull, RelatedIsNull)
     self.assertIsInstance(b_isnull.lhs, SimpleCol)
     self.assertEqual(b_isnull.lhs.target, ObjectC._meta.get_field('objectb'))
开发者ID:EmadMokhtar,项目名称:django,代码行数:13,代码来源:test_query.py

示例8: test_complex_query

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
    def test_complex_query(self):
        query = Query(Author)
        where = query.build_where(Q(num__gt=2) | Q(num__lt=0))
        self.assertEqual(where.connector, OR)

        lookup = where.children[0]
        self.assertIsInstance(lookup, GreaterThan)
        self.assertEqual(lookup.rhs, 2)
        self.assertEqual(lookup.lhs.target, Author._meta.get_field('num'))

        lookup = where.children[1]
        self.assertIsInstance(lookup, LessThan)
        self.assertEqual(lookup.rhs, 0)
        self.assertEqual(lookup.lhs.target, Author._meta.get_field('num'))
开发者ID:EmadMokhtar,项目名称:django,代码行数:16,代码来源:test_query.py

示例9: test_simplecol_query

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
    def test_simplecol_query(self):
        query = Query(Author)
        where = query.build_where(Q(num__gt=2, name__isnull=False) | Q(num__lt=F('id')))

        name_isnull_lookup, num_gt_lookup = where.children[0].children
        self.assertIsInstance(num_gt_lookup, GreaterThan)
        self.assertIsInstance(num_gt_lookup.lhs, SimpleCol)
        self.assertIsInstance(name_isnull_lookup, IsNull)
        self.assertIsInstance(name_isnull_lookup.lhs, SimpleCol)

        num_lt_lookup = where.children[1]
        self.assertIsInstance(num_lt_lookup, LessThan)
        self.assertIsInstance(num_lt_lookup.rhs, SimpleCol)
        self.assertIsInstance(num_lt_lookup.lhs, SimpleCol)
开发者ID:MattBlack85,项目名称:django,代码行数:16,代码来源:test_query.py

示例10: test_foreign_key_f

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def test_foreign_key_f(self):
     query = Query(Ranking)
     with self.assertRaises(FieldError):
         query.build_where(Q(rank__gt=F('author__num')))
开发者ID:EmadMokhtar,项目名称:django,代码行数:6,代码来源:test_query.py

示例11: test_foreign_key

# 需要导入模块: from django.db.models.sql.query import Query [as 别名]
# 或者: from django.db.models.sql.query.Query import build_where [as 别名]
 def test_foreign_key(self):
     query = Query(Item)
     msg = 'Joined field references are not permitted in this query'
     with self.assertRaisesMessage(FieldError, msg):
         query.build_where(Q(creator__num__gt=2))
开发者ID:EmadMokhtar,项目名称:django,代码行数:7,代码来源:test_query.py


注:本文中的django.db.models.sql.query.Query.build_where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。