使用django-haystack对模板中的总搜索对象进行计数 [英] Count total search objects count in template using django-haystack

查看:251
本文介绍了使用django-haystack对模板中的总搜索对象进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django haystack与xapian作为后端搜索引擎。我正在使用 FacetedSearchView FacetedSearchForm 来进行搜索。我已经通过 searchqueryset 到我的 urls.py FacetSearchView >文件。



但问题是我无法访问模板中的 searchqueryset 。我想做的是计算 searchqueryset 中找到的对象数。在shell中我可以使用S earchQuerySet()。filter(content =foo)。count(),我怎么能在模板中这样做?请指导。我想要匹配搜索的对象总数。

解决方案

干草堆使用标准的django分页: https://docs.djangoproject.com/en/dev/topics/pagination/



显示 {{page.object_list | length}} {{page.paginator.count}} 页面上的结果 {{page.number}} {{page.paginator.num_pages}}


I am using django haystack with xapian as the backend search engine. I am using FacetedSearchView and FacetedSearchForm for faceting over the search. I have passed searchqueryset to the FacetSearchView in my urls.py file.

But the problem is I cannot access that searchqueryset in template. All I want to do is count the number of objects in searchqueryset found.

In shell I could achieve it using SearchQuerySet().filter(content="foo").count(), how can I do that similarly in the template? Please guide. I want the total number of objects matching the search.

解决方案

Haystack uses the standard django pagination: https://docs.djangoproject.com/en/dev/topics/pagination/

Showing {{ page.object_list|length }} of {{ page.paginator.count }} Results on Page {{ page.number }} of {{ page.paginator.num_pages }}

这篇关于使用django-haystack对模板中的总搜索对象进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆