I am trying to add djangohaystack
simple backend
into my django app. I've tried following the tutorial but none of the objects in Person
are being rendered in the template. I have no idea what I might have missed. The {% if query %}
condition is satisfied but the next for loop is not satisfied and No results to display
is displayed.
models.py
class Person(models.Model):
person_name = models.CharField(max_length=200)
score = models.FloatField()
search_indexes.py
class PersonIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
person_name = indexes.CharField(model_attr='person_name')
def get_model(self):
return Person
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
site.register(Person, PersonIndex)
note_text
{{ object.person_name }}
search.html
{% if query %}
<h3>Results</h3>
{% for result in page.object_list %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.person_name }}</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}
{% endif %}
This is all that I have . I know simplebackend
is not supposed to do an extensive search but it must return results after exact name search and I need to deploy this on heroku and heroku only supports search engines as pricey add-ons.Any idea if their is something that I might have missed?
/*********************edit 1********************/
class PersonDetail(generics.RetrieveUpdateDestroyAPIView):
serializer_class = PersonSerializer
permission_classes = (IsAuthenticatedOrReadOnly,)
def get_object(self):
person_id = self.kwargs.get('pk',None)
return Movie.objects.get(pk=person_id)
full traceback -
AttributeError at /search/
'module' object has no attribute 'get_model'
Exception Location: C:\Users\final\lib\site-packages\haystack\forms.py in get_models, line 110
Traceback:
File "C:\Users\final\lib\site-packages\django\core\handlers\base.py" in get_response
149.response = self.process_exception_by_middleware(e, request)
File "C:\Users\final\lib\site-packages\django\core\handlers\base.py" in get_response
147.response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\final\lib\site-packages\haystack\views.py" in __call__
51.self.results = self.get_results()
File "C:\Users\final\lib\site-packages\haystack\views.py" in get_results
91.return self.form.search()
File "C:\Users\final\lib\site-packages\haystack\forms.py" in search
116.return sqs.models(*self.get_models())
File "C:\Users\final\lib\site-packages\haystack\forms.py" in get_models
110.search_models.append(models.get_model(*model.split('.')))
Exception Type: AttributeError at /search/
Exception Value: 'module' object has no attribute 'get_model'
try to test
# -*- coding: utf-8 -*-
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "[look at manage.py]")
import django
from django.core.management import call_command
from haystack.query import SearchQuerySet
django.setup()
call_command('rebuild_index')
print SearchQuerySet().all()
I looked in haystack sources, get_model moved to apps in django19 this is working example