本文整理汇总了Python中django.db.models.sql.where.WhereNode.add方法的典型用法代码示例。如果您正苦于以下问题:Python WhereNode.add方法的具体用法?Python WhereNode.add怎么用?Python WhereNode.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.sql.where.WhereNode
的用法示例。
在下文中一共展示了WhereNode.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_or
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_or(self):
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND)
where.add((Constraint("givenName", "givenName", CharField()), 'exact',
"bar"), OR)
self.assertEquals(where_as_ldap(where), ("(|(cn=foo)(givenName=bar))",
[]))
示例2: test_char_field_in
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_in(self):
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'in', ["foo", "bar"]), AND)
self.assertEquals(where_as_ldap(where), ("(|(cn=foo)(cn=bar))", []))
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'in', ["(foo)", "(bar)"]), AND)
self.assertEquals(where_as_ldap(where), ("(|(cn=\\28foo\\29)(cn=\\28bar\\29))", []))
示例3: test_char_field_exact
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_exact(self):
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'exact', "test"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=test)", []))
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'exact', "(test)"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=\\28test\\29)", []))
示例4: test_list_field_contains
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_list_field_contains(self):
where = WhereNode()
where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', 'foouser'), AND)
self.assertEquals(where_as_ldap(where), ("(memberUid=foouser)", []))
where = WhereNode()
where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', '(foouser)'), AND)
self.assertEquals(where_as_ldap(where), ("(memberUid=\\28foouser\\29)", []))
示例5: test_char_field_contains
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_contains(self):
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'contains', "test"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=*test*)", []))
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'contains', "te*st"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=*te\\2ast*)", []))
示例6: test_list_field_contains
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_list_field_contains(self):
where = WhereNode()
where.add(self._build_lookup("memberUid", 'contains', 'foouser', field=ListField), AND)
self.assertEqual(where_as_ldap(where), "(memberUid=foouser)")
where = WhereNode()
where.add(self._build_lookup("memberUid", 'contains', '(foouser)', field=ListField), AND)
self.assertEqual(where_as_ldap(where), "(memberUid=\\28foouser\\29)")
示例7: test_char_field_in
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_in(self):
where = WhereNode()
where.add(self._build_lookup("cn", 'in', ["foo", "bar"]), AND)
self.assertEqual(where_as_ldap(where), "(|(cn=foo)(cn=bar))")
where = WhereNode()
where.add(self._build_lookup("cn", 'in', ["(foo)", "(bar)"]), AND)
self.assertEqual(where_as_ldap(where), "(|(cn=\\28foo\\29)(cn=\\28bar\\29))")
示例8: test_char_field_contains
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_contains(self):
where = WhereNode()
where.add(self._build_lookup("cn", 'contains', "test"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*test*)")
where = WhereNode()
where.add(self._build_lookup("cn", 'contains', "te*st"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*te\\2ast*)")
示例9: test_char_field_exact
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_exact(self):
where = WhereNode()
where.add(self._build_lookup('cn', 'exact', "test"), AND)
self.assertEqual(where_as_ldap(where), "(cn=test)")
where = WhereNode()
where.add(self._build_lookup('cn', 'exact', "(test)"), AND)
self.assertEqual(where_as_ldap(where), "(cn=\\28test\\29)")
示例10: test_list_field_startswith
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_list_field_startswith(self):
where = WhereNode()
where.add((Constraint("cn", "cn", ListField()), 'startswith', "test"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=test*)", []))
where = WhereNode()
where.add((Constraint("cn", "cn", ListField()), 'startswith', "te*st"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=te\\2ast*)", []))
示例11: test_char_field_endswith
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_endswith(self):
where = WhereNode()
where.add(self._build_lookup("cn", 'endswith', "test"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*test)")
where = WhereNode()
where.add(self._build_lookup("cn", 'endswith', "te*st"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*te\\2ast)")
示例12: test_char_field_endswith
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_char_field_endswith(self):
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'endswith', "test"),
AND)
self.assertEqual(where_as_ldap(where), ("(cn=*test)", []))
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'endswith', "te*st"),
AND)
self.assertEqual(where_as_ldap(where), ("(cn=*te\\2ast)", []))
示例13: as_sql
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def as_sql(self, compiler, connection):
if isinstance(self.lhs, MultiColSource):
assert self.rhs_is_direct_value()
self.rhs = get_normalized_value(self.rhs, self.lhs)
from django.db.models.sql.where import WhereNode, AND
root_constraint = WhereNode()
for target, source, val in zip(self.lhs.targets, self.lhs.sources, self.rhs):
lookup_class = target.get_lookup(self.lookup_name)
root_constraint.add(
lookup_class(target.get_col(self.lhs.alias, source), val), AND)
return root_constraint.as_sql(compiler, connection)
return super().as_sql(compiler, connection)
示例14: as_sql
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def as_sql(self, compiler, connection):
if isinstance(self.lhs, MultiColSource):
# For multicolumn lookups we need to build a multicolumn where clause.
# This clause is either a SubqueryConstraint (for values that need to be compiled to
# SQL) or a OR-combined list of (col1 = val1 AND col2 = val2 AND ...) clauses.
from django.db.models.sql.where import WhereNode, SubqueryConstraint, AND, OR
root_constraint = WhereNode(connector=OR)
if self.rhs_is_direct_value():
values = [get_normalized_value(value, self.lhs) for value in self.rhs]
for value in values:
value_constraint = WhereNode()
for source, target, val in zip(self.lhs.sources, self.lhs.targets, value):
lookup_class = target.get_lookup('exact')
lookup = lookup_class(target.get_col(self.lhs.alias, source), val)
value_constraint.add(lookup, AND)
root_constraint.add(value_constraint, OR)
else:
root_constraint.add(
SubqueryConstraint(
self.lhs.alias, [target.column for target in self.lhs.targets],
[source.name for source in self.lhs.sources], self.rhs),
AND)
return root_constraint.as_sql(compiler, connection)
else:
return super(RelatedIn, self).as_sql(compiler, connection)
示例15: test_integer_field
# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
def test_integer_field(self):
where = WhereNode()
where.add(self._build_lookup("uid", 'exact', 1, field=fields.IntegerField), AND)
self.assertEqual(self._where_as_ldap(where), "(uid=1)")
where = WhereNode()
where.add(self._build_lookup("uid", 'gte', 1, field=fields.IntegerField), AND)
self.assertEqual(self._where_as_ldap(where), "(uid>=1)")
where = WhereNode()
where.add(self._build_lookup("uid", 'lte', 1, field=fields.IntegerField), AND)
self.assertEqual(self._where_as_ldap(where), "(uid<=1)")
where = WhereNode()
where.add(self._build_lookup("uid", 'in', [1, 2], field=fields.IntegerField), AND)
self.assertEqual(self._where_as_ldap(where), "(|(uid=1)(uid=2))")