Python 如何更改Django中Haystack的document=True字段的名称?

Python 如何更改Django中Haystack的document=True字段的名称?,python,django,solr,django-haystack,Python,Django,Solr,Django Haystack,我想使用haystack,但我所有的模型都有“body”作为它们的文本字段名。不过,所有车型都是一样的 现在我得到了这个错误: All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field. Offending index is '<qna.search_indexes.QuestionIndex object at 0x2435328>'. 这是唯一的一个!它冒

我想使用haystack,但我所有的模型都有“body”作为它们的文本字段名。不过,所有车型都是一样的

现在我得到了这个错误:

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

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

我在haystack源代码中看到了你的错误。看起来此字段()的名称有一个设置:

稍后在该文件()中,它会检查以确保您的索引名匹配,如果他们不一致,则会出现您看到的错误:

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_字段设置为“body”,看起来应该这样做

self.document_field = getattr(settings, 'HAYSTACK_DOCUMENT_FIELD', 'text')
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))