• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.has_int_pk函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中watson.models.has_int_pk函数的典型用法代码示例。如果您正苦于以下问题:Python has_int_pk函数的具体用法?Python has_int_pk怎么用?Python has_int_pk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: do_filter

 def do_filter(self, engine_slug, queryset, search_text):
     """Performs the full text filter."""
     model = queryset.model
     content_type = ContentType.objects.get_for_model(model)
     pk = model._meta.pk
     if has_int_pk(model):
         ref_name = "object_id_int"
     else:
         ref_name = "object_id"
     return queryset.extra(
         tables = ("watson_searchentry",),
         where = (
             "watson_searchentry.engine_slug = %s",
             "watson_searchentry.search_tsv @@ to_tsquery('{search_config}', %s)".format(
                 search_config = self.search_config
             ),
             "watson_searchentry.{ref_name} = {table_name}.{pk_name}".format(
                 ref_name = ref_name,
                 table_name = connection.ops.quote_name(model._meta.db_table),
                 pk_name = connection.ops.quote_name(pk.db_column or pk.attname),
             ),
             "watson_searchentry.content_type_id = %s"
         ),
         params = (engine_slug, self.escape_postgres_query(search_text), content_type.id),
     )
开发者ID:clime,项目名称:django-watson,代码行数:25,代码来源:backends.py


示例2: _get_entries_for_obj

    def _get_entries_for_obj(self, obj):
        """Returns a queryset of entries associate with the given obj."""
        from django.contrib.contenttypes.models import ContentType

        model = obj.__class__
        content_type = ContentType.objects.get_for_model(model)
        object_id = force_text(obj.pk)
        # Get the basic list of search entries.
        search_entries = SearchEntry.objects.filter(
            content_type = content_type,
            engine_slug = self._engine_slug,
        )
        if has_int_pk(model):
            # Do a fast indexed lookup.
            object_id_int = int(obj.pk)
            search_entries = search_entries.filter(
                object_id_int = object_id_int,
            )
        else:
            # Alas, have to do a slow unindexed lookup.
            object_id_int = None
            search_entries = search_entries.filter(
                object_id = object_id,
            )
        return object_id_int, search_entries
开发者ID:codingjoe,项目名称:django-watson,代码行数:25,代码来源:registration.py


示例3: _create_model_filter

 def _create_model_filter(self, models):
     """Creates a filter for the given model/queryset list."""
     filters = Q()
     for model in models:
         filter = Q()
         # Process querysets.
         if isinstance(model, QuerySet):
             sub_queryset = model
             model = model.model
             queryset = sub_queryset.values_list("pk", flat=True)
             if has_int_pk(model):
                 filter &= Q(
                     object_id_int__in = queryset,
                 )
             else:
                 live_ids = list(queryset)
                 if live_ids:
                     filter &= Q(
                         object_id__in = live_ids,
                     )
                 else:
                     # HACK: There is a bug in Django (https://code.djangoproject.com/ticket/15145) that messes up __in queries when the iterable is empty.
                     # This bit of nonsense ensures that this aspect of the query will be impossible to fulfill.
                     filter &= Q(
                         content_type = ContentType.objects.get_for_model(model).id + 1,
                     )
         # Add the model to the filter.
         content_type = ContentType.objects.get_for_model(model)
         filter &= Q(
             content_type = content_type,
         )
         # Combine with the other filters.
         filters |= filter
     return filters
开发者ID:Fitblip,项目名称:django-watson,代码行数:34,代码来源:registration.py


示例4: _create_model_filter

 def _create_model_filter(self, models, backend):
     """Creates a filter for the given model/queryset list."""
     from django.contrib.contenttypes.models import ContentType
     from watson.models import has_int_pk
     filters = Q()
     for model in models:
         filter = Q()
         # Process querysets.
         if isinstance(model, QuerySet):
             sub_queryset = model
             model = model.model
             queryset = sub_queryset.values_list("pk", flat=True)
             if has_int_pk(model):
                 filter &= Q(
                     object_id_int__in=queryset,
                 )
             else:
                 queryset = queryset.annotate(
                     watson_pk_str=RawSQL(backend.do_string_cast(
                         connections[queryset.db],
                         model._meta.pk.db_column or model._meta.pk.attname,
                     ), ()),
                 ).values_list("watson_pk_str", flat=True)
                 filter &= Q(
                     object_id__in=queryset,
                 )
         # Add the model to the filter.
         content_type = ContentType.objects.get_for_model(model)
         filter &= Q(
             content_type=content_type,
         )
         # Combine with the other filters.
         filters |= filter
     return filters
开发者ID:etianen,项目名称:django-watson,代码行数:34,代码来源:search.py


示例5: do_filter

 def do_filter(self, engine_slug, queryset, search_text):
     """Performs the full text filter."""
     model = queryset.model
     content_type = ContentType.objects.get_for_model(model)
     connection = connections[queryset.db]
     pk = model._meta.pk
     if has_int_pk(model):
         ref_name = "object_id_int"
     else:
         ref_name = "object_id"
     return queryset.extra(
         tables=("watson_searchentry",),
         where=(
             "watson_searchentry.engine_slug = %s",
             "MATCH (watson_searchentry.title, watson_searchentry.description, watson_searchentry.content) "
             "AGAINST (%s IN BOOLEAN MODE)",
             "watson_searchentry.{ref_name} = {table_name}.{pk_name}".format(
                 ref_name=ref_name,
                 table_name=connection.ops.quote_name(model._meta.db_table),
                 pk_name=connection.ops.quote_name(pk.db_column or pk.attname),
             ),
             "watson_searchentry.content_type_id = %s",
         ),
         params=(engine_slug, self._format_query(search_text), content_type.id),
     )
开发者ID:etianen,项目名称:django-watson,代码行数:25,代码来源:backends.py


示例6: _create_model_filter

 def _create_model_filter(self, models):
     """Creates a filter for the given model/queryset list."""
     from django.contrib.contenttypes.models import ContentType
     from watson.models import has_int_pk
     filters = Q()
     for model in models:
         filter = Q()
         # Process querysets.
         if isinstance(model, QuerySet):
             sub_queryset = model
             model = model.model
             queryset = sub_queryset.values_list("pk", flat=True)
             if has_int_pk(model):
                 filter &= Q(
                     object_id_int__in=queryset,
                 )
             else:
                 filter &= Q(
                     object_id__in=queryset,
                 )
         # Add the model to the filter.
         content_type = ContentType.objects.get_for_model(model)
         filter &= Q(
             content_type=content_type,
         )
         # Combine with the other filters.
         filters |= filter
     return filters
开发者ID:moggers87,项目名称:django-watson,代码行数:28,代码来源:search.py


示例7: register

 def register(self, model, adapter_cls=SearchAdapter, **field_overrides):
     """
     Registers the given model with this search engine.
     
     If the given model is already registered with this search engine, a
     RegistrationError will be raised.
     """
     # Add in custom live filters.
     if isinstance(model, QuerySet):
         live_queryset = model
         model = model.model
         field_overrides["get_live_queryset"] = lambda self_: live_queryset.all()
     # Check for existing registration.
     if self.is_registered(model):
         raise RegistrationError("{model!r} is already registered with this search engine".format(
             model = model,
         ))
     # Perform any customization.
     if field_overrides:
         adapter_cls = type("Custom" + adapter_cls.__name__, (adapter_cls,), field_overrides)
     # Perform the registration.
     adapter_obj = adapter_cls(model)
     self._registered_models[model] = adapter_obj
     # Add in a generic relation, if not exists.
     if not hasattr(model, "searchentry_set"):
         if has_int_pk(model):
             object_id_field = "object_id_int"
         else:
             object_id_field = "object_id"
         generic_relation = generic.GenericRelation(
             SearchEntry,
             object_id_field = object_id_field,
         )
         model.searchentry_set = generic_relation
         generic_relation.contribute_to_class(model, "searchentry_set")
     # Connect to the signalling framework.
     post_save.connect(self._post_save_receiver, model)
     pre_delete.connect(self._pre_delete_receiver, model)
开发者ID:bfitzsimmons,项目名称:django-watson,代码行数:38,代码来源:registration.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python search.search函数代码示例发布时间:2022-05-26
下一篇:
Python messages.Request类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap