Django-Haystack: 'NoneType' object has no attribute '_default_manager'
Asked Answered
D

3

5

I am trying to add a haystack search to my base.html to include it globally on my site. It errors though when i submit a search

I am getting:

Django-Haystack: 'NoneType' object has no attribute '_default_manager'

I have added it to INSTALLED_APPS and my urls.py. ./manage.py rebuild_index runs fine.

models.py:

class Site(models.Model):
    site_name = models.CharField(max_length=100, blank=False, null=False)
    site_manager = models.CharField(max_length=100, blank=False, null=False)
    address_1 = models.CharField(max_length=100, blank=False, null=False)
    address_2 = models.CharField(max_length=100, blank=True, null=True)
    address_3 = models.CharField(max_length=100, blank=True, null=True)
    town_city = models.CharField(max_length=100, verbose_name='Town/City')
    county = models.CharField(max_length=100, blank=False, null=False)
    postcode = models.CharField(max_length=100, blank=False, null=False)
    region = models.CharField(max_length=100, blank=True, null=True)
    tel = models.CharField(max_length=100, blank=False, null=False)
    email = models.EmailField(max_length=100, blank=False, null=False)

    creation = models.DateField(auto_now_add=True)
    last_modified = models.DateField(auto_now=True)

    def __unicode__(self):
        return self.site_name

SiteIndex.py:

class SiteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    site_name = indexes.CharField(model_attr='site_name')
    site_manager = indexes.CharField(model_attr='site_manager')
    address_1 = indexes.CharField(model_attr='address_1')
    address_2 = indexes.CharField(model_attr='address_2')
    address_3 = indexes.CharField(model_attr='address_3')
    town_city = indexes.CharField(model_attr='town_city')
    county = indexes.CharField(model_attr='county')
    postcode = indexes.CharField(model_attr='postcode')
    region = indexes.CharField(model_attr='region')
    tel = indexes.CharField(model_attr='tel')
    email = indexes.CharField(model_attr='email')
    creation = indexes.DateField(model_attr='creation')
    last_modified = indexes.DateField(model_attr='last_modified')

    def get_model(self):
        return Site

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

site_text.txt:

{{ object.site_name }}
{{ object.site_manager }}
# ect

base.html

<form action="/search/" method="get">
     <input type="text" name="q">
     <input type="submit" value="Search">
</form>

UPDATE:

I have noticed that, if i downgrade to DJango 1.8. It works. Is there an issue with more uptodate versions of django?

Discarnate answered 18/1, 2016 at 10:27 Comment(0)
B
8

The error is because your version of Haystack does not support your Django version. You need to upgrade your version of django-haystack if you want to use Django 1.9+

Support for Django 1.9 was added in Haystack 2.5 and support for Django 1.10 was added in Haystack 2.5.1.

Bornie answered 18/1, 2016 at 12:58 Comment(0)
P
4

You may install latest version from github (as in signal answer), but using pip:

pip uninstall django-haystack
pip install -e git+https://github.com/django-haystack/django-haystack.git#egg=django-haystack
Pirozzo answered 29/2, 2016 at 12:51 Comment(1)
also works (newest pip): pip install git+https://github.com/django-haystack/django-haystack.gitBabylonian
E
2

I worked around this by installing the latest version from github (currently 2.5.dev0):

pip uninstall django-haystack
git clone https://github.com/django-haystack/django-haystack
cd django-haystack
python setup.py install
Elisavetgrad answered 16/2, 2016 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.