2014-10-28 204 views
0

我想使用草垛,但我所有的模型都有“body”作为它们的文本字段名称。但所有型号都是一样的。如何更改文档的名称= Django中Haystack的True字段?

现在我得到这个错误:

All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field. Offending index is '<qna.search_indexes.QuestionIndex object at 0x2435328>'. 

这就是索引文件:

进口日期时间 从草垛进口指数 从qna.models导入问题

class QuestionIndex(indexes.SearchIndex, indexes.Indexable): 
    subject = indexes.CharField(document=False, use_template=False) 
    body = indexes.CharField(document=True, use_template=True, model_attr='user') 
    pub_date = indexes.DateTimeField(model_attr='pub_date') 

    def get_model(self): 
     return Question 

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

它是只有一个!什么是冒犯?据我所知,字段名称不必是“文本”,它只需要在每个字段上都是相同的。但它是唯一的领域!我必须更改一些配置吗?这可能是什么原因???

回答

1

我在干草堆里看到了你的错误。它看起来像有此字段的名称设置(https://github.com/toastdriven/django-haystack/blob/master/haystack/utils/loading.py#L154):

self.document_field = getattr(settings, 'HAYSTACK_DOCUMENT_FIELD', 'text') 

在该文件(https://github.com/toastdriven/django-haystack/blob/master/haystack/utils/loading.py#L222)后来它检查,以确保您的索引名的比赛,并与你看到如果错误炸毁他们不同意:

if field_object.index_fieldname != self.document_field: 
    raise SearchFieldError("All 'SearchIndex' classes must use the same '%s' fieldname for the 'document=True' field. Offending index is '%s'." % (self.document_field, index)) 

如果设置HAYSTACK_DOCUMENT_FIELD为“体”,在你的设置,它看起来像应该这样做。

相关问题