使用 django-haystack 计算模板中的搜索对象总数

2023-12-25

我使用 django haystack 和 xapian 作为后端搜索引擎。我在用FacetedSearchView and FacetedSearchForm用于对搜索进行分面。我已经通过了searchqueryset to the FacetSearchView in my urls.py file.

但问题是我无法访问它searchqueryset在模板中。我想做的就是计算其中的对象数量searchqueryset found.

在 shell 中我可以使用 S 来实现它earchQuerySet().filter(content="foo").count(),我怎样才能在模板中做到类似的事情?请指导。我想要匹配搜索的对象总数。


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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 django-haystack 计算模板中的搜索对象总数 的相关文章

随机推荐