本文整理汇总了Python中search.forms.SearchForm.search_qs方法的典型用法代码示例。如果您正苦于以下问题:Python SearchForm.search_qs方法的具体用法?Python SearchForm.search_qs怎么用?Python SearchForm.search_qs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类search.forms.SearchForm
的用法示例。
在下文中一共展示了SearchForm.search_qs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from search.forms import SearchForm [as 别名]
# 或者: from search.forms.SearchForm import search_qs [as 别名]
def index(request):
accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
user_langs = get_user_languages_from_request(request)
if 'q' in request.REQUEST:
form = SearchForm(request.user, user_langs, request.REQUEST)
else:
form = SearchForm(request.user, user_langs)
qs = SearchQuerySet().none()
display_mode = 'all'
if form.is_valid():
qs = form.search_qs(SearchQuerySet().models(Video))
display_mode = form.cleaned_data.get('display', 'all')
if settings.HAYSTACK_SEARCH_ENGINE == 'dummy' and settings.DEBUG:
q = request.REQUEST.get('q', '')
qs = Video.objects.filter(title__icontains=q)
context = {
'query': request.REQUEST.get('q', ''),
'form': form,
'display_mode': display_mode
}
return object_list(request, queryset=qs,
paginate_by=30,
template_name='search/index.html',
template_object_name='result',
extra_context=context)
示例2: search
# 需要导入模块: from search.forms import SearchForm [as 别名]
# 或者: from search.forms.SearchForm import search_qs [as 别名]
def search(self, rdata, user, testing=False):
sqs = SearchQuerySet().result_class(VideoSearchResult) \
.models(Video)
rdata['q'] = rdata['q'] or u' '
q = rdata.get('q')
if q:
sqs = SearchForm.apply_query(q, sqs)
form = SearchForm(rdata, sqs=sqs)
else:
form = SearchForm(rdata)
if form.is_valid():
qs = form.search_qs(sqs)
else:
qs = SearchQuerySet().none()
#result = [item.object for item in qs]
#qs1 = Video.objects.filter(title__contains=rdata['q'])
#for o in qs1:
# if not o in result:
# print o.title
display_views = form.get_display_views()
output = render_page(rdata.get('page', 1), qs, 20, display_views=display_views)
output['sidebar'] = render_to_string('search/_sidebar.html', dict(form=form, rdata=rdata))
if testing:
output['sqs'] = qs
return output