I've hit a dead end with my django 1.9.5 project. Im running Haystack 2.4.1 and Whoosh 2.7.4 as a search-engine. Here is my poblem:
When accessing followng view:
def search_titles(request):
resources = SearchQuerySet().autocomplete(content_auto=request.POST.get('search_text', ''))
return render_to_response('ajax_search.html', {'resources' : resources})
with ajax_search.html looking as follows:
{% if resources.count > 0 %}
{% for resource in resources %}
<li>{{resource.object.title}} _ {{resource.object}}</li>
{% endfor %}
{% else %}
<li>None to show</li>
{% endif %}
The search works just fine. Depending on what I search for I get the exact amount of results I should be getting, however at the line
<li>{{resource.object.title}} _ {{resource.object}}</li>
they all show up as
- _ None
(.object.title being blank and .object being None).
In case it helps, here is my search_indexes.py:
class ResourceIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
published = indexes.DateField(model_attr='published')
content_auto = indexes.EdgeNgramField(model_attr='title')
def get_model(self): return Resource
def index_queryset(self, using=None): return self.get_model().objects.all()
and resource_text.txt:
{{object.title}}
{{object.subtitle}}
The Resource-model looks like this:
class Resource(models.Model):
authors = models.ManyToManyField(Person, related_name='resources_authored')
title = models.CharField(max_length=300, unique=True)
subtitle = models.CharField(max_length=300, unique=True)
published = models.DateField('date published')
def __str__(self): return self.title
def get_absolute_url(self): return '/resources/%i/' % self.id
class Meta:
ordering = ['-published', 'title']
get_latest_by = 'published'
Anybody got any ideas why I get None-objects when calling .object on the results in the SearchQuerySet?