【问题标题】:How to get the count of search results in haystack search?如何在干草堆搜索中获取搜索结果的计数?
【发布时间】:2012-01-18 20:47:16
【问题描述】:

我正在使用 django-haystack 进行搜索。如何在模板中显示在数据库中使用 haystack 搜索找到的搜索结果计数?我的意思是我必须在哪里更改我的 haystack 视图才能获得 searchquery 的计数。非常感谢帮助。

【问题讨论】:

标签: django django-haystack


【解决方案1】:

SearchQuerySet.count() 怎么样?在模板中,它将是{{ mysearchqueryset.count }}

http://readthedocs.org/docs/django-haystack/en/latest/searchqueryset_api.html#count

【讨论】:

  • 在我的 haystack urls 中我已经完成了 qs = SearchQuerySet().order_by('-created').count() 并且在我的模板中我使用的是 {{ query.count}} 但它给出了某种属性错误:“int”对象没有属性“auto_query”请帮忙。
  • 当然,如果您调用一次count(),您将不再拥有searchqueryset,而是int。从您的视图中删除 count 呼叫。如果您通过qs = SearchQuerySet().auto_query('my_query_here') 的观点,那么在您的模板中输入{{ qs.count }},您将获得您的计数。
  • 我明白了。必须在 haystack 中的 form.py 中定义我的 on 函数计数。谢谢你的帮助。
猜你喜欢
  • 2012-05-22
  • 2012-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-10
  • 2017-11-07
  • 2018-04-04
  • 1970-01-01
相关资源
最近更新 更多