Django haystack奇怪的错误?

Django haystack奇怪的错误?,django,django-haystack,Django,Django Haystack,我正在尝试使用haystack+whoosh将搜索添加到站点。我都是手工做的。 我的模型: class News(models.Model): title = models.CharField(max_length=250) slug = models.SlugField('URL', unique=True) article = RichTextUploadingField() head_pic= models.ImageField(u'Заглавное из

我正在尝试使用haystack+whoosh将搜索添加到站点。我都是手工做的。 我的模型:

class News(models.Model):
    title = models.CharField(max_length=250)
    slug = models.SlugField('URL', unique=True)
    article = RichTextUploadingField()
    head_pic= models.ImageField(u'Заглавное изображение', upload_to='head_news_photo_store',blank=True, null=True)
    pub_date = models.DateTimeField('Дата публикации',auto_now_add=True)
    category = models.ForeignKey(Category)
    author = models.ForeignKey(settings.AUTH_USER_MODEL)
    is_top_news = models.BooleanField(u'Сделать топ новостью?', default=False)
    is_important = models.BooleanField(u'Добавить в слайдер?', default=False)
    is_main = models.BooleanField(u'Добавить в главное?', default=False)
我的搜索_index.py如下:

from haystack import indexes
import datetime
from .models import News


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


    def get_model(self):
        return News

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())
当我在triyng发出搜索请求时,出现下一个错误:

Traceback:

File "C:\Python 3.5\lib\site-packages\haystack\query.py" in post_process_results
  213.                     index = ui.get_index(model)

File "C:\Python 3.5\lib\site-packages\haystack\utils\loading.py" in get_index
  308.             raise NotHandled('The model %s is not registered' % model_klass)

During handling of the above exception (The model None is not registered), another exception occurred:

File "C:\Python 3.5\lib\site-packages\django\core\handlers\base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "C:\Python 3.5\lib\site-packages\django\core\handlers\base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Python 3.5\lib\site-packages\haystack\views.py" in __call__
  53.         return self.create_response()

File "C:\Python 3.5\lib\site-packages\haystack\views.py" in create_response
  133.         (paginator, page) = self.build_page()

File "C:\Python 3.5\lib\site-packages\haystack\views.py" in build_page
  110.         self.results[start_offset:start_offset + self.results_per_page]

File "C:\Python 3.5\lib\site-packages\haystack\query.py" in __getitem__
  272.                 self._fill_cache(start, bound)

File "C:\Python 3.5\lib\site-packages\haystack\query.py" in _fill_cache
  191.         to_cache = self.post_process_results(results)

File "C:\Python 3.5\lib\site-packages\haystack\query.py" in post_process_results
  219.                     loaded_objects[model] = model._default_manager.in_bulk(models_pks[model])

Exception Type: AttributeError at /search/
Exception Value: 'NoneType' object has no attribute '_default_manager'
本地变量:

result      <SearchResult: news.news (pk='2')>
ui      <haystack.utils.loading.UnifiedIndex object at 0x03EDC3F0>
results     [<SearchResult: news.news (pk='2')>]
loaded_objects      {}
model       None
to_cache        []
models_pks      {None: ['2']}
self        Error in formatting: AttributeError: 'NoneType' object has no attribute '_default_manager'
结果
用户界面
结果[]
加载的_对象{}
模型无
到_缓存[]
模型_pks{None:['2']}
格式设置中出现自身错误:AttributeError:“非类型”对象没有属性“\u默认值\u管理器”

我的新闻模型有什么问题?

如果您使用的是Django 1.9,Haystack的最新版本(v2.3.2)不支持它。但我认为这个问题已经解决并合并到主分支中,因此希望Django 1.9支持很快就会到来。

在进行搜索之前是否运行了rebuild_index命令?@AleksanderGordienko检查这是否有帮助: