Question

I have the following problem with Haystack and Django. That what I am trying to do is to filter the model Books some objects and get the max and the min price. Basically bellow is the query, where sq is dynamically generated query:

partial_query = SearchQuerySet().models(Books).filter(sq)

This return about 10 results. After I checked the documentation of Haystack (http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html), found that stats('price'), stats_results() will work fine for me, but for some reason, the only output what I see is None. Below is the code:

partial_query = SearchQuerySet().models(Listing).filter(sq).stats('price')
partial_query.stats_results()

After a few test, I found that actually the following print do that, what they expect to do.

print(partial_query[0].price) #for example 123
print(partial_query) #list with about 10 objects

Also if you know any other methods to get max and min price from this query, please feel free to share with me :). I will be grateful for any help. Thanks.

Was it helpful?

Solution

From your tags it sounds like you're using elasticsearch but as per the haystack documentation

This is supported on Solr only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top