django-haystack:对象没有属性“Indexable”;

发布于 2025-01-02 04:53:18 字数 2929 浏览 2 评论 0原文

我是 django-haystack 的新手,我正在尝试遵循入门指南。但是,我遇到 AttributeError: object has no attribute 'Indexable'。

在我的 settins.py 中,我有:

HAYSTACK_SITECONF = 'mysite.search_sites'
HAYSTACK_SEARCH_ENGINE = 'solr'
HAYSTACK_SOLR_URL = 'http://127.0.0.1:8983/solr'

在我的 models.py (位于我的名为“searchapp”的应用程序中)中,我有:

from django.db import models
from django.contrib.auth.models import User


class baymodel(models.Model):
    id = models.IntegerField(primary_key=True)
    domain = models.CharField(max_length=765, db_column='Domain', blank=True)
    category = models.CharField(max_length=765, db_column='Category', blank=True) 
    link = models.CharField(max_length=765, db_column='Link') 
    name = models.CharField(max_length=765, db_column='Name', blank=True) 
    cur_timestamp = models.DateTimeField()

    def __unicode__(self):
      return self.name

    def index_queryset(self):
    """Used when the entire index for model is updated."""
       return self.objects.all()

在我的 search_indexes.py 中(位于我的 searchapp 目录中),然后我有:

import datetime
from haystack import indexes
from searchapp.models import baymodel


class baymodelIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr='user')
    link = indexes.CharField(model_attr='link')
    domain = indexes.CharField(model_attr='domain')
    pub_date = indexes.DateTimeField(model_attr='cur_timestamp')

def get_model(self):
    return baymodel

site.register(baymodel, baymodelIndex)

在 search_sites.py 中,我有:

import haystack
haystack.autodiscover()

我已经按照他们的说明安装了 solr,并且我可以看到漂亮的 solr 管理页面。

现在,当我这样做时:

sudo python manage.py build_solr_schema

我被抛出一个 AttributeError:

AttributeError: 'module' object has no attribute 'Indexable'

I have attempts to do:

python ./manage.py shell

,我再次得到:

AttributeError: 'module' object has no attribute 'Indexable'

如果我只是进入 python 并尝试导入 haystack,我得到:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import haystack
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/haystack/__init__.py", line 26, in <module>
raise ImproperlyConfigured("You must define the HAYSTACK_SITECONF setting before using the search framework.")
django.core.exceptions.ImproperlyConfigured: You must define the HAYSTACK_SITECONF  setting before using the search framework.

这很奇怪,因为我的 settings.py 确实指定了 HAYSTACK_CONF 和python ./manage.py shell 抛出 AttributeError。

有没有人遇到过类似的错误?谢谢。

Iam new to django-haystack, and I am trying to follow the getting started guide. However, I encounter an AttributeError: object has no attribute 'Indexable'.

In my settins.py, I have:

HAYSTACK_SITECONF = 'mysite.search_sites'
HAYSTACK_SEARCH_ENGINE = 'solr'
HAYSTACK_SOLR_URL = 'http://127.0.0.1:8983/solr'

In my models.py (which resides in my app called "searchapp"), I have:

from django.db import models
from django.contrib.auth.models import User


class baymodel(models.Model):
    id = models.IntegerField(primary_key=True)
    domain = models.CharField(max_length=765, db_column='Domain', blank=True)
    category = models.CharField(max_length=765, db_column='Category', blank=True) 
    link = models.CharField(max_length=765, db_column='Link') 
    name = models.CharField(max_length=765, db_column='Name', blank=True) 
    cur_timestamp = models.DateTimeField()

    def __unicode__(self):
      return self.name

    def index_queryset(self):
    """Used when the entire index for model is updated."""
       return self.objects.all()

In my search_indexes.py (residing in my searchapp directory), I then have:

import datetime
from haystack import indexes
from searchapp.models import baymodel


class baymodelIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr='user')
    link = indexes.CharField(model_attr='link')
    domain = indexes.CharField(model_attr='domain')
    pub_date = indexes.DateTimeField(model_attr='cur_timestamp')

def get_model(self):
    return baymodel

site.register(baymodel, baymodelIndex)

In search_sites.py, I have:

import haystack
haystack.autodiscover()

I have installed solr according to their instructions, and I can see the pretty solr admin page.

Now, when I do:

sudo python manage.py build_solr_schema

I get thrown an AttributeError:

AttributeError: 'module' object has no attribute 'Indexable'

I have tried to do:

python ./manage.py shell

and I again get:

AttributeError: 'module' object has no attribute 'Indexable'

If I simply go into python and try and import haystack, I get:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import haystack
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/haystack/__init__.py", line 26, in <module>
raise ImproperlyConfigured("You must define the HAYSTACK_SITECONF setting before using the search framework.")
django.core.exceptions.ImproperlyConfigured: You must define the HAYSTACK_SITECONF  setting before using the search framework.

which is strange because my settings.py does specify HAYSTACK_CONF and python ./manage.py shell throws an AttributeError.

Has anyone encountered a similar error? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2025-01-09 04:53:18

代码基于正在开发的 haystack 2,v2 改变了索引的定义方式。安装的版本是 1.2,因此正确的文档可在 此处找到,例如

class BayModelIndex(indexes.SearchIndex, indexes.Indexable):

应该是(正确导入SearchIndex):

class BayModelIndex(SearchIndex):

索引类也需要定义index_queryset,而不是get_model,它应该返回一个查询集。

Code is based on haystack 2 which is in development, v2 changes the way indexes are defined. Installed version is 1.2 so the correct documents are available here, e.g.

class BayModelIndex(indexes.SearchIndex, indexes.Indexable):

should be (with correct import of SearchIndex):

class BayModelIndex(SearchIndex):

also instead of get_model, the index class needs index_queryset defined, which should return a QuerySet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文