4

I am using django-haystack for searching. How can i display in the template the count of search results found using haystack search in database? I mean where do i have to change my haystack views to get the count of searchquery. Would really appreciate help.

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
G Gill
  • 1,087
  • 1
  • 12
  • 24
  • 2
    I think you can find a better answer here : http://stackoverflow.com/questions/8261462/count-total-search-objects-count-in-template-using-django-haystack – Franck Jan 23 '12 at 09:26

1 Answers1

4

How about SearchQuerySet.count()? In the template, it would be {{ mysearchqueryset.count }}

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

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245
  • in my haystack urls i have done qs = SearchQuerySet().order_by('-created').count() and in my template i am using {{ query.count}} but it is giving some kind of Attribute error : 'int' object has no attribute 'auto_query' please help. – G Gill Jan 21 '12 at 09:00
  • 2
    Naturally, if you call `count()` once, you no longer have a `searchqueryset` but an `int`. Remove the `count` call from your view. If you pass your view that `qs = SearchQuerySet().auto_query('my_query_here')`, then in your template type `{{ qs.count }}` you'll get your count. – Yuji 'Tomita' Tomita Jan 21 '12 at 18:44
  • i got it. had to define my on function count in form.py in haystack. Thank you for help. – G Gill Jan 21 '12 at 23:11