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


Python lookups.Exact方法代码示例

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


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

示例1: test_spanning_relations_with_custom_lookup_in_search_fields

# 需要导入模块: from django.db.models import lookups [as 别名]
# 或者: from django.db.models.lookups import Exact [as 别名]
def test_spanning_relations_with_custom_lookup_in_search_fields(self):
        hype = Group.objects.create(name='The Hype')
        concert = Concert.objects.create(name='Woodstock', group=hype)
        vox = Musician.objects.create(name='Vox', age=20)
        Membership.objects.create(music=vox, group=hype)
        # Register a custom lookup on IntegerField to ensure that field
        # traversing logic in ModelAdmin.get_search_results() works.
        IntegerField.register_lookup(Exact, 'exactly')
        try:
            m = ConcertAdmin(Concert, custom_site)
            m.search_fields = ['group__members__age__exactly']

            request = self.factory.get('/', data={SEARCH_VAR: '20'})
            request.user = self.superuser
            cl = m.get_changelist_instance(request)
            self.assertCountEqual(cl.queryset, [concert])

            request = self.factory.get('/', data={SEARCH_VAR: '21'})
            request.user = self.superuser
            cl = m.get_changelist_instance(request)
            self.assertCountEqual(cl.queryset, [])
        finally:
            IntegerField._unregister_lookup(Exact, 'exactly') 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例2: test_transform

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

示例3: resolve_lookup_expected_type

# 需要导入模块: from django.db.models import lookups [as 别名]
# 或者: from django.db.models.lookups import Exact [as 别名]
def resolve_lookup_expected_type(self, ctx: MethodContext, model_cls: Type[Model], lookup: str) -> MypyType:
        query = Query(model_cls)
        try:
            lookup_parts, field_parts, is_expression = query.solve_lookup_type(lookup)
            if is_expression:
                return AnyType(TypeOfAny.explicit)
        except FieldError as exc:
            ctx.api.fail(exc.args[0], ctx.context)
            return AnyType(TypeOfAny.from_error)

        field = self._resolve_field_from_parts(field_parts, model_cls)

        lookup_cls = None
        if lookup_parts:
            lookup = lookup_parts[-1]
            lookup_cls = field.get_lookup(lookup)
            if lookup_cls is None:
                # unknown lookup
                return AnyType(TypeOfAny.explicit)

        if lookup_cls is None or isinstance(lookup_cls, Exact):
            return self.get_field_lookup_exact_type(helpers.get_typechecker_api(ctx), field)

        assert lookup_cls is not None

        lookup_info = helpers.lookup_class_typeinfo(helpers.get_typechecker_api(ctx), lookup_cls)
        if lookup_info is None:
            return AnyType(TypeOfAny.explicit)

        for lookup_base in helpers.iter_bases(lookup_info):
            if lookup_base.args and isinstance(lookup_base.args[0], Instance):
                lookup_type: MypyType = lookup_base.args[0]
                # if it's Field, consider lookup_type a __get__ of current field
                if (isinstance(lookup_type, Instance)
                        and lookup_type.type.fullname == fullnames.FIELD_FULLNAME):
                    field_info = helpers.lookup_class_typeinfo(helpers.get_typechecker_api(ctx), field.__class__)
                    if field_info is None:
                        return AnyType(TypeOfAny.explicit)
                    lookup_type = helpers.get_private_descriptor_type(field_info, '_pyi_private_get_type',
                                                                      is_nullable=field.null)
                return lookup_type

        return AnyType(TypeOfAny.explicit) 
开发者ID:typeddjango,项目名称:django-stubs,代码行数:45,代码来源:context.py


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