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

六眼飞鱼酱① 提交于 2019-12-07 04:56:22

问题


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?


回答1:


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.




回答2:


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



回答3:


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


来源:https://stackoverflow.com/questions/34852424/django-haystack-nonetype-object-has-no-attribute-default-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!