1

I set up a very simple project to try out Haystack using a Whoosh engine, mostly following the example in the documentation. I installed everything using pip and no version numbers, so I should have the latest release versions.

I'm getting this error and I have no idea what I'm supposed to do now, I cannot find anything similar though I've scoured Google. Please help!

The project folder structure is very simple, with one app called cat.

    project
    |-cat
    |  |-migrations
    |  |-admin.py, apps.py, models.py, search_indexes.py
    |-templates
    |  |-search
    |     |-indexes
    |     |  |-cat
    |     |     |-cat_text.txt
    |     |-search.html
    |-manage.py, settings.py, urls.py

The error I'm getting is:

    Environment:


    Request Method: GET
    Request URL: http://localhost:8000/search/?q=felix&models=cat.cat

    Django Version: 1.9.4
    Python Version: 2.7.10
    Installed Applications:
    ['django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'haystack',
     'cat',]
    Installed Middleware:
    ['django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware']



    Traceback:

    File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      149.                     response = self.process_exception_by_middleware(e, request)

    File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

    File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/haystack/views.py" in __call__
      51.         self.results = self.get_results()

    File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/haystack/views.py" in get_results
      91.         return self.form.search()

    File "/Users/lebouuski/projects/django/lib/python2.7/site-packages/haystack/forms.py" in search
      116.         return sqs.models(*self.get_models())

    File "/Users/lebouuski/projects/django/lib/python2.7/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'

models.py:

class Cat(models.Model):
  name = models.CharField(max_length=255)
  birth_date = models.DateField(default=datetime.date.today)
  bio = models.TextField(blank=True)
  created = models.DateTimeField(default=datetime.datetime.now)
  updated = models.DateTimeField(default=datetime.datetime.now)

  def __unicode__(self):
    return self.name

  @models.permalink
  def get_absolute_url(self):
    return ('cat_detail', [], {'id': self.id})

search_indexes.py

class CatIndex(indexes.BasicSearchIndex, indexes.Indexable):

  def get_model(self):
    return Cat
Sushil
  • 371
  • 1
  • 3
  • 11

2 Answers2

3

For anyone else struggling with this, this is all due to a little change in Django 1.9, in which the get_model() method is moved to the django.apps.apps module, and is no longer available from django.db

The issue is resolved now in Haystack community, so updating to the newest version, from their GitHub repository (and not PyPI) must solve it.

The following should solve it:

pip install git+https://github.com/django-haystack/django-haystack.git

Or you can simply downgrade to Django 1.8 as Sam suggested. You can find more over this issue here

Iman Akbari
  • 2,167
  • 26
  • 31
0

Solution: downgrade Django from 1.9 to 1.8

sudo pip install Django==1.8

Motivations here: link

Massimo Variolo
  • 4,669
  • 6
  • 38
  • 64
  • I went to a LOT of effort upgrading my project from an old version of Django to 1.9, I'd rather not now go back. The Haystack authors have suggested getting the unreleased build, and that works. Thanks for replying! – Sushil Apr 16 '16 at 05:19