本文整理汇总了Python中django.contrib.admin.utils.lookup_needs_distinct方法的典型用法代码示例。如果您正苦于以下问题:Python utils.lookup_needs_distinct方法的具体用法?Python utils.lookup_needs_distinct怎么用?Python utils.lookup_needs_distinct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.utils
的用法示例。
在下文中一共展示了utils.lookup_needs_distinct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search_queryset
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import lookup_needs_distinct [as 别名]
def search_queryset(self, queryset, search_term, **kwargs):
if not search_term or not self.search_fields:
return queryset
orm_lookups = ['%s__icontains' % str(search_field)
for search_field in self.search_fields]
for bit in search_term.split():
or_queries = [Q(**{orm_lookup: bit})
for orm_lookup in orm_lookups]
queryset = queryset.filter(reduce(operator.or_, or_queries))
opts = queryset.model._meta
for search_spec in orm_lookups:
if lookup_needs_distinct(opts, search_spec):
return queryset.distinct()
return queryset