本文整理汇总了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;未经允许,请勿转载。 |
请发表评论