[Answer]-How to change the name of the document=True field of Haystack in Django?

1👍

I saw your error in the haystack source. It looks like there is a setting for the name of this field (https://github.com/toastdriven/django-haystack/blob/master/haystack/utils/loading.py#L154):

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

Later in that file (https://github.com/toastdriven/django-haystack/blob/master/haystack/utils/loading.py#L222) it checks to make sure that your index name matches and blows up with the error you saw if they don’t agree:

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

If you set HAYSTACK_DOCUMENT_FIELD to “body” in your settings, it looks like that should do it.

Leave a comment