本文整理汇总了Python中django.db.models.CharField.register_lookup方法的典型用法代码示例。如果您正苦于以下问题:Python CharField.register_lookup方法的具体用法?Python CharField.register_lookup怎么用?Python CharField.register_lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.CharField
的用法示例。
在下文中一共展示了CharField.register_lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ready
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
def ready(self):
# Connections may already exist before we are called.
for conn in connections.all():
if conn.connection is not None:
register_type_handlers(conn)
connection_created.connect(register_type_handlers)
CharField.register_lookup(Unaccent)
TextField.register_lookup(Unaccent)
CharField.register_lookup(SearchLookup)
TextField.register_lookup(SearchLookup)
CharField.register_lookup(TrigramSimilar)
TextField.register_lookup(TrigramSimilar)
示例2: test_transform
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_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'))
示例3: test_transform
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_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)
示例4: test_upper_transform
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_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')
示例5: test_length_transform
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_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')
示例6: test_trim_transform
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_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)
示例7: test_func_transform_bilateral
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_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')
示例8: ready
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
def ready(self):
connection_created.connect(register_hstore_handler)
CharField.register_lookup(Unaccent)
TextField.register_lookup(Unaccent)
CharField.register_lookup(SearchLookup)
TextField.register_lookup(SearchLookup)
CharField.register_lookup(TrigramSimilar)
TextField.register_lookup(TrigramSimilar)
示例9: add_lookups
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
def add_lookups(self):
from django.db.models import CharField, TextField
from django_mysql.models.lookups import (
CaseSensitiveExact, Soundex, SoundsLike
)
CharField.register_lookup(CaseSensitiveExact)
CharField.register_lookup(SoundsLike)
CharField.register_lookup(Soundex)
TextField.register_lookup(CaseSensitiveExact)
TextField.register_lookup(SoundsLike)
TextField.register_lookup(Soundex)
示例10: ready
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
def ready(self):
# Connections may already exist before we are called.
for conn in connections.all():
if conn.vendor == 'postgresql':
conn.introspection.data_types_reverse.update({
3802: 'django.contrib.postgres.fields.JSONField',
3904: 'django.contrib.postgres.fields.IntegerRangeField',
3906: 'django.contrib.postgres.fields.DecimalRangeField',
3910: 'django.contrib.postgres.fields.DateTimeRangeField',
3912: 'django.contrib.postgres.fields.DateRangeField',
3926: 'django.contrib.postgres.fields.BigIntegerRangeField',
})
if conn.connection is not None:
register_type_handlers(conn)
connection_created.connect(register_type_handlers)
CharField.register_lookup(Unaccent)
TextField.register_lookup(Unaccent)
CharField.register_lookup(SearchLookup)
TextField.register_lookup(SearchLookup)
CharField.register_lookup(TrigramSimilar)
TextField.register_lookup(TrigramSimilar)
示例11: ready
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
def ready(self):
CharField.register_lookup(Unaccent)
TextField.register_lookup(Unaccent)
示例12: Levenshtein
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
class Levenshtein(Transform):
lookup_name = 'levenshtein'
def as_sql(self, qn, connection):
lhs, lhs_params = qn.compile(self.lhs)
rhs, rhs_params = self.process_rhs(qn, connection)
params = lhs_params + rhs_params
return 'levenshtein(%s, %s)' % (lhs), params
@property
def output_field(self):
return PositiveIntegerField()
class DoubleMetaphone(Transform):
lookup_name = 'dmetaphone'
def as_sql(self, qn, connection):
lhs, params = qn.compile(self.lhs)
return 'dmetaphone(%s)' % (lhs), params
@property
def output_field(self):
return CharField()
CharField.register_lookup(SoundsLike)
CharField.register_lookup(Soundex)
CharField.register_lookup(Difference)
CharField.register_lookup(DoubleMetaphone)
示例13: ready
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
def ready(self):
connection_created.connect(register_hstore_handler)
CharField.register_lookup(Unaccent)
TextField.register_lookup(Unaccent)
示例14: UpperCase
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
#************************************************
from django.db.models import Transform, Field
class UpperCase(Transform):
lookup_name = 'upper'
bilateral = True
def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
return "UPPER(%s)" % lhs, params
from django.db.models import CharField, TextField
CharField.register_lookup(UpperCase)
TextField.register_lookup(UpperCase)
class AbsoluteValue(Transform):
lookup_name = 'abs'
def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
return "ABS(%s)" % lhs, params
@property
def output_field(self):
return FloatField()
#*****************************8
示例15:
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
from django.apps import AppConfig