DjangoHaystack,和MongoEngin一起呼呼

2024-04-26 02:43:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为django项目使用Mongodb数据库。在

我想在网站上有搜索功能。在

搜索_索引.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):
    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();      

我正在跟踪http://django-haystack.readthedocs.org/en/latest/debugging.html以解决问题:

键入命令后:

^{pr2}$

出现以下错误:

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'

在此方面的任何帮助都将不胜感激。在

谢谢你!在


Tags: inpyselfgetmodelinitlibpackages