AttributeError at /search/ 'NoneType' object has no attribute '_default_manager' Request Method: GET Request URL: http://127.0.0.1:8000/search/?q=desktop Django Version: 1.9 Exception Type: AttributeError Exception Value:'NoneType' object has no attribute '_default_manager' Exception Location: /home/ankit/venv/django/lib/python3.4/site-packages/haystack/query.py in post_process_results, line 219 Python Executable: /home/ankit/venv/django/bin/python Python Version: 3.4.3 Python Path: ['/home/ankit/venv/django/p2', '/home/ankit/venv/django/lib/python3.4', '/home/ankit/venv/django/lib/python3.4/plat-x86_64-linux-gnu', '/home/ankit/venv/django/lib/python3.4/lib-dynload', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/home/ankit/venv/django/lib/python3.4/site-packages'] Server time: Sun, 27 Dec 2015 10:29:28 +0000
我的search_indexes.py
import datetime
from haystack import indexes
from inventory.models import Item
class ItemIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
pub_date = indexes.DateTimeField(model_attr='pub_date')
content_auto = indexes.EdgeNgramField(model_attr='title')
def get_model(self):
return Item
def index_queryset(self, using=None):
return self.get_model().objects.all()
我的settings.py文件
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}
答案 0 :(得分:1)
django.db.model.get_model
在1.9中不再可用,因此在调用None
时会返回django.db.models.get_model
,但在最近的提交中(从1月3日起){{1} }}用于在使用Django 1.7或更高版本时使用utils.app_loading.py
,否则使用旧的django.apps.apps.get_model
。
因此,最好升级到最新的开发版django.db.models._get_models
。