问题描述
我正在尝试获取10个对象,如:
I am trying to get the to 10 objects like :
q_auth = SearchQuerySet().filter(content=validate_query)
q_auth = q_auth[:10]
print type(q_auth)
输出我想要的是:< class'haystack.query.SearchQuerySet'>
但我得到的是< type'list'> / code>。
The output I want is:
<class 'haystack.query.SearchQuerySet'>
but I am getting is <type 'list'>
.
有些人可以帮我吗?
推荐答案
查看,您将看到 q_auth [:10]
返回结果列表。一个 SearchQuerySet
是懒惰的,可能没有所有的结果,直到你用切片检索,即 q_auth [:10]
。
Looking at the source, you will see that
q_auth[:10]
returns a list of results. A SearchQuerySet
is lazy and might not have all the results until you retrieve them with slicing, i.e. q_auth[:10]
.
只要做:
first_results = q_auth[:10]
并访问结果:
first_results[0]
我建议不要这样做: / p>
I recommend not to do this:
q_auth = q_auth[:10]
因为您的实例
q_auth
SearchQuerySet
将无法再检索更多结果。
because your instance
q_auth
of SearchQuerySet
would not be available for retrieving more results later.
这篇关于如何从SearchQuerySet获取n个搜索对象而不更改类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!