Count total search objects count in template using django-haystack

 ̄綄美尐妖づ 提交于 2019-12-09 05:39:30

问题


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.


回答1:


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 }}




回答2:


If you want to show the result range instead of page number, e.g. "Results 21-40 of 1001", You can do

Results {{ page.start_index }} - {{ page.end_index }} of {{ page.paginator.count }}



回答3:


{{ page.object_list | length }}


来源:https://stackoverflow.com/questions/8261462/count-total-search-objects-count-in-template-using-django-haystack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!