本文整理汇总了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'))
示例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)
示例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')
示例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')
示例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)
示例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')
示例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)