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


Python CharField._unregister_lookup方法代码示例

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


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

示例1: test_transform

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import _unregister_lookup [as 别名]
 def test_transform(self):
     query = Query(Author)
     CharField.register_lookup(Lower, 'lower')
     try:
         where = query.build_where(~Q(name__lower='foo'))
     finally:
         CharField._unregister_lookup(Lower, 'lower')
     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:NewbiePanda,项目名称:django,代码行数:14,代码来源:test_query.py

示例2: test_transform

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import _unregister_lookup [as 别名]
 def test_transform(self):
     new_name = self.t1.name.upper()
     self.assertNotEqual(self.t1.name, new_name)
     Tag.objects.create(name=new_name)
     CharField.register_lookup(Lower)
     try:
         self.assertCountEqual(
             Tag.objects.order_by().distinct('name__lower'),
             [self.t1, self.t2, self.t3, self.t4, self.t5],
         )
     finally:
         CharField._unregister_lookup(Lower)
开发者ID:CodeMonk,项目名称:django,代码行数:14,代码来源:tests.py

示例3: test_upper_transform

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import _unregister_lookup [as 别名]
 def test_upper_transform(self):
     try:
         CharField.register_lookup(Upper, 'upper')
         Author.objects.create(name='John Smith', alias='smithj')
         Author.objects.create(name='Rhonda')
         authors = Author.objects.filter(name__upper__exact='JOHN SMITH')
         self.assertQuerysetEqual(
             authors.order_by('name'), [
                 'John Smith',
             ],
             lambda a: a.name
         )
     finally:
         CharField._unregister_lookup(Upper, 'upper')
开发者ID:CrazyChief,项目名称:django,代码行数:16,代码来源:tests.py

示例4: test_length_transform

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import _unregister_lookup [as 别名]
 def test_length_transform(self):
     try:
         CharField.register_lookup(Length, 'length')
         Author.objects.create(name='John Smith', alias='smithj')
         Author.objects.create(name='Rhonda')
         authors = Author.objects.filter(name__length__gt=7)
         self.assertQuerysetEqual(
             authors.order_by('name'), [
                 'John Smith',
             ],
             lambda a: a.name
         )
     finally:
         CharField._unregister_lookup(Length, 'length')
开发者ID:CrazyChief,项目名称:django,代码行数:16,代码来源:tests.py

示例5: test_trim_transform

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import _unregister_lookup [as 别名]
 def test_trim_transform(self):
     Author.objects.create(name=' John  ')
     Author.objects.create(name='Rhonda')
     tests = (
         (LTrim, 'John  '),
         (RTrim, ' John'),
         (Trim, 'John'),
     )
     for transform, trimmed_name in tests:
         with self.subTest(transform=transform):
             try:
                 CharField.register_lookup(transform)
                 authors = Author.objects.filter(**{'name__%s' % transform.lookup_name: trimmed_name})
                 self.assertQuerysetEqual(authors, [' John  '], lambda a: a.name)
             finally:
                 CharField._unregister_lookup(transform)
开发者ID:NewbiePanda,项目名称:django,代码行数:18,代码来源:test_trim.py

示例6: test_func_transform_bilateral

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import _unregister_lookup [as 别名]
    def test_func_transform_bilateral(self):
        class UpperBilateral(Upper):
            bilateral = True

        try:
            CharField.register_lookup(UpperBilateral, 'upper')
            Author.objects.create(name='John Smith', alias='smithj')
            Author.objects.create(name='Rhonda')
            authors = Author.objects.filter(name__upper__exact='john smith')
            self.assertQuerysetEqual(
                authors.order_by('name'), [
                    'John Smith',
                ],
                lambda a: a.name
            )
        finally:
            CharField._unregister_lookup(UpperBilateral, 'upper')
开发者ID:CrazyChief,项目名称:django,代码行数:19,代码来源:tests.py

示例7: uninstall_if_needed

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import _unregister_lookup [as 别名]
def uninstall_if_needed(setting, value, enter, **kwargs):
    """
    Undo the effects of PostgresConfig.ready() when django.contrib.postgres
    is "uninstalled" by override_settings().
    """
    if not enter and setting == 'INSTALLED_APPS' and 'django.contrib.postgres' not in set(value):
        connection_created.disconnect(register_type_handlers)
        CharField._unregister_lookup(Unaccent)
        TextField._unregister_lookup(Unaccent)
        CharField._unregister_lookup(SearchLookup)
        TextField._unregister_lookup(SearchLookup)
        CharField._unregister_lookup(TrigramSimilar)
        TextField._unregister_lookup(TrigramSimilar)
        # Disconnect this receiver until the next time this app is installed
        # and ready() connects it again to prevent unnecessary processing on
        # each setting change.
        setting_changed.disconnect(uninstall_if_needed)
开发者ID:RaphaelKimmig,项目名称:django,代码行数:19,代码来源:apps.py


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