django haystack AttributeError:' NoneType'对象没有属性' _meta'

时间:2015-04-13 17:58:06

标签: django django-haystack

我正在使用django 1.7.7和django-haystack 2.1.1和elasticsearch。虽然以下代码正常工作:

>>> from accounts.models import CustomUser
>>> SearchQuerySet().models(CustomUser)
[<SearchResult: accounts.customuser (pk=u'552bc0ac1d41c80fe8015208')>]

但是,当我跑步时

>>> SearchQuerySet()

我在stacktrace中遇到以下错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/query.py", line 82, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE])
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/query.py", line 266, in __getitem__
    self._fill_cache(start, bound)
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/query.py", line 166, in _fill_cache
    results = self.query.get_results(**kwargs)
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 645, in get_results
    self.run(**kwargs)
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 918, in run
    results = self.backend.search(final_query, **search_kwargs)
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 35, in wrapper
    return func(obj, query_string, *args, **kwargs)
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 475, in search
    search_kwargs = self.build_search_kwargs(query_string, **kwargs)
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 402, in build_search_kwargs
    model_choices = self.build_models_list()
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 196, in build_models_list
    models.append(get_model_ct(model))
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/utils/__init__.py", line 76, in get_model_ct
    return "%s.%s" % get_model_ct_tuple(model)
  File "/home/kunal/virtualenvs/test/local/lib/python2.7/site-packages/haystack/utils/__init__.py", line 70, in get_model_ct_tuple
    return (model._meta.app_label, model._meta.model_name)
AttributeError: 'NoneType' object has no attribute '_meta'

我无法弄清楚如何在SearchQuerySet结果中指定模型(可选),并且没有指定它给出错误的模型。

0 个答案:

没有答案