Haystack和Django存在以下问题。我正在尝试做的是过滤模型Book的一些对象并获得最大和最小价格。基本上,下面是查询,其中sq是动态生成的查询:
partial_query = SearchQuerySet().models(Books).filter(sq)
此返回大约10个结果。
在检查了Haystack(http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html)的文档后,发现stats('price'),stats_results()对我来说很好用,但是由于某种原因,我看到的唯一输出是None。下面是代码:
partial_query = SearchQuerySet().models(Listing).filter(sq).stats('price')
partial_query.stats_results()
经过几次测试,我发现实际上以下打印品可以达到他们期望的效果。
print(partial_query[0].price) #for example 123
print(partial_query) #list with about 10 objects
另外,如果您知道通过此查询获取最高和最低价格的任何其他方法,请随时与我分享:)。我将不胜感激。谢谢。
最佳答案
从标签上听起来好像您正在使用Elasticsearch,但按照haystack documentation
This is supported on Solr only.
关于python - 干草堆:stats()和stats_results()不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221032/