doctorsherlock doctorsherlock - 1 year ago 106
Python Question

Django-Haystack giving attribute error?

I am trying to use Haystack and Whoosh with my Django app. I followed the steps on Haystack docs, but i am getting this error when i do a search

AttributeError at /search/
'module' object has no attribute 'get_model' -

import datetime
from haystack import indexes
from movies.models import Movie

class MovieIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')

def get_model(self):
return Movie

def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()

I couldn't find help on this error anywhere, what am i doing wrong?

Stacktrace -


Request Method: GET
Request URL:

Django Version: 1.9.1
Python Version: 2.7.6
Installed Applications:
Installed Middleware:


File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/django/core/handlers/" in get_response
149. response = self.process_exception_by_middleware(e, request)

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/django/core/handlers/" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/" in __call__
51. self.results = self.get_results()

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/" in get_results
91. return

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/" in search
116. return sqs.models(*self.get_models())

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/" 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'

Python 2.7.6

Django 1.9.1

Haystack 2.4.1

Whoosh 2.7.0

Answer Source

That looks to me like a compatibility issue between the version of Haystack and Django. Django recently reworked the get_model system (I think in 1.9), so if you've upgraded Django and not Haystack - or perhaps vice-versa - that may be the issue.

I'm guessing the get_model() references in your index file are a potential red-herring, and that the issue is within the Haystack internals, as it's not able to find that method where it expects to.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download