haystack 应该 return 一个模型对象还是它的一部分?

Is haystack supposed to return a model object or just pieces of it?

我正在学习使用 haystack 的教程,它们的视图模板是这样设置的

{% for result in results %}

    {% with post=result.object %}

    <h4><a href="{{ post.get_absolute_url }}">{{ result.title }}</a></h4>
    {{ post.body|truncatewords:5 }}
    {% endwith %}
    {% empty %}
    <p>There are no results for your query.</p>
{% endfor %}

这是我感兴趣的部分

{% with post=result.object %}

还有这个

<h4><a href="{{ post.get_absolute_url }}">{{ result.title }}</a></h4>

通常从我读过的语法是

result.object.get_absolute_url

但他显然做到了

with post=result.object 

让自己的作品无对象

我的东西是这样的;我无权访问 get_absolute_url。我没有返回实际对象。只有使用它获得的部分

publish = indexes.DateTimeField(model_attr='publish')
title = indexes.CharField(model_attr='title')
body = indexes.CharField(model_attr='body')

有了这些,我可以做到:

{% for result in results %}
    {% with post=result.object %}
    {{result.publish}}<br>
    {{result.title}}<br>
    {{result.body}}<br><hr>
    #......

但这不是真正的物体,只是从碎片中剥离出来我怎样才能得到实际的物体,这样我就可以使用

href="{{result.object.get_absolute_url}}"

不必这样做

slug = indexes.CharField(model_attr='slug')

然后必须这样做

href="{% url 'blog:post_detail' result.slug %}

有对象,在result.object。您已使用 with 语句将其分配给 post,但随后您完全忽略了该变量。