示例#1
0
    def test_func_transform_bilateral_multivalue(self):
        class UpperBilateral(Upper):
            bilateral = True

        try:
            CharField.register_lookup(UpperBilateral)
            Author.objects.create(name='John Smith', alias='smithj')
            Author.objects.create(name='Rhonda')
            authors = Author.objects.filter(
                name__upper__in=['john smith', 'rhonda'])
            self.assertQuerysetEqual(authors.order_by('name'), [
                'John Smith',
                'Rhonda',
            ], lambda a: a.name)
        finally:
            CharField._unregister_lookup(UpperBilateral)
示例#2
0
 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)
示例#3
0
文件: apps.py 项目: iMerica/dj-models
 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:
                 'djmodels.contrib.postgres.fields.JSONField',
                 3904:
                 'djmodels.contrib.postgres.fields.IntegerRangeField',
                 3906:
                 'djmodels.contrib.postgres.fields.FloatRangeField',
                 3910:
                 'djmodels.contrib.postgres.fields.DateTimeRangeField',
                 3912:
                 'djmodels.contrib.postgres.fields.DateRangeField',
                 3926:
                 'djmodels.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)