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


Python CharField.register_lookup方法代码示例

本文整理汇总了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)
开发者ID:KIKUYA-Takumi,项目名称:django,代码行数:14,代码来源:apps.py

示例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'))
开发者ID:NewbiePanda,项目名称:django,代码行数:14,代码来源:test_query.py

示例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)
开发者ID:CodeMonk,项目名称:django,代码行数:14,代码来源:tests.py

示例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')
开发者ID:CrazyChief,项目名称:django,代码行数:16,代码来源:tests.py

示例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')
开发者ID:CrazyChief,项目名称:django,代码行数:16,代码来源:tests.py

示例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)
开发者ID:NewbiePanda,项目名称:django,代码行数:18,代码来源:test_trim.py

示例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')
开发者ID:CrazyChief,项目名称:django,代码行数:19,代码来源:tests.py

示例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)
开发者ID:0xool,项目名称:DjangoTutorial,代码行数:10,代码来源:apps.py

示例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)
开发者ID:adamyp,项目名称:django-mysql,代码行数:14,代码来源:apps.py

示例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)
开发者ID:GravyHands,项目名称:django,代码行数:23,代码来源:apps.py

示例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)
开发者ID:DjangoBD,项目名称:django-rest-framework-filters,代码行数:5,代码来源:apps.py

示例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)
开发者ID:jaywhy13,项目名称:django-pgfuzzy,代码行数:32,代码来源:models.py

示例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)
开发者ID:aakash201,项目名称:OnlineJudge,代码行数:6,代码来源:apps.py

示例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
开发者ID:poleha,项目名称:py_examples,代码行数:32,代码来源:django_lookup.py

示例15:

# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import register_lookup [as 别名]
from django.apps import AppConfig
开发者ID:letouriste001,项目名称:SmartForest_2.0,代码行数:3,代码来源:apps.py


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