Python Django Haystack,带着MongoEngine的嗖嗖声
我正在为django项目使用Mongodb数据库 我想在网站上有搜索功能 search_index.py文件包含:Python Django Haystack,带着MongoEngine的嗖嗖声,python,django,mongodb,django-haystack,Python,Django,Mongodb,Django Haystack,我正在为django项目使用Mongodb数据库 我想在网站上有搜索功能 search_index.py文件包含: import datetime from haystack import indexes from beauty.models import ALL_PRODUCTS from django.template.defaultfilters import title class offersIndex(indexes.SearchIndex, indexes.Indexable):
import datetime
from haystack import indexes
from beauty.models import ALL_PRODUCTS
from django.template.defaultfilters import title
class offersIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
content_auto = indexes.EdgeNgramField(model_attr='ProductTitle')
def get_model(self):
return ALL_PRODUCTS
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all();
我正在按照以下步骤解决问题:
键入命令后:
>>> sqs = SearchQuerySet().all()
>>> sqs.count()
出现以下错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/haystack/query.py", line 485, in count
print self
File "/usr/local/lib/python2.7/dist-packages/haystack/query.py", line 96, in __len__
self._result_count = self.query.get_count()
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 626, in get_count
self.run()
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 563, in run
results = self.backend.search(final_query, **search_kwargs)
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 35, in wrapper
return func(obj, query_string, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/whoosh_backend.py", line 385, in search
model_choices = self.build_models_list()
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 196, in build_models_list
models.append(get_model_ct(model))
File "/usr/local/lib/python2.7/dist-packages/haystack/utils/__init__.py", line 81, in get_model_ct
return "%s.%s" % get_model_ct_tuple(model)
File "/usr/local/lib/python2.7/dist-packages/haystack/utils/__init__.py", line 75, in get_model_ct_tuple
return (model._meta.app_label, model._meta.model_name)
AttributeError: 'MetaDict' object has no attribute 'app_label'
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/usr/local/lib/python2.7/dist packages/haystack/query.py”,第485行,计数
打印自我
文件“/usr/local/lib/python2.7/dist packages/haystack/query.py”,第96行,在__
self.\u result\u count=self.query.get\u count()
文件“/usr/local/lib/python2.7/dist-packages/haystack/backends/_init__.py”,第626行,在get\u count中
self.run()
文件“/usr/local/lib/python2.7/dist packages/haystack/backends/__init__.py”,第563行,正在运行
results=self.backend.search(最终查询,**搜索)
文件“/usr/local/lib/python2.7/dist-packages/haystack/backends/__-init___.py”,第35行,在包装器中
return func(对象、查询字符串、*args、**kwargs)
搜索中的文件“/usr/local/lib/python2.7/dist packages/haystack/backends/whoosh_backend.py”,第385行
model\u choices=self.build\u models\u list()
文件“/usr/local/lib/python2.7/dist-packages/haystack/backends/__-init___.py”,第196行,在构建模型列表中
models.append(get_model_ct(model))
文件“/usr/local/lib/python2.7/dist-packages/haystack/utils/________.py”,第81行,在get_model_ct中
返回“%s.%s”%get\u model\u ct\u元组(model)
文件“/usr/local/lib/python2.7/dist-packages/haystack/utils/_________.py”,第75行,在get_-model_-ct_元组中
返回(model.\u meta.app\u标签、model.\u meta.model\u名称)
AttributeError:“MetaDict”对象没有属性“app\u label”
非常感谢您在这方面的任何帮助
谢谢大家!