Search code examples
django-haystack

How to index CommentsField in Haystack?


I have a comments = CommentsField() in my Django model. I am wondering how can I index this CommentsField() type in Haystack as indexes.CharField(model_attr='comments').


Solution

  • You may do,

    comment = indexes.CharField(model_attr='comments')
    

    And prepare comment field above as,

    prepare_comment(self,obj):
        return obj.comment
    

    obj.comment is the actual content of the comment

    Refer link below for more on prepare http://django-haystack.readthedocs.org/en/latest/searchfield_api.html?highlight=prepare#SearchField.prepare