Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django haystack strange error?

I'm triyng to add search to site by using haystack + whoosh. I've done all by manual. My model:

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)

And my search_indexes.py here:

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())

When I'm triyng to make search request getting the next error:

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'

Local vars:

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'

What's wrong with my News model?


1 Answers

If you're using Django 1.9, the latest release of Haystack (v2.3.2) does not support it. But I think this particular issue has been fixed and merged into the master branch, so hopefully Django 1.9 support is coming soon.

like image 192
aris Avatar answered Sep 23 '26 16:09

aris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!