[Answer]-Display Foreign Key values in Django haystack search results

1๐Ÿ‘

I hope you have created a SearchIndex which will index UserProfessional and not UserProfile.

class UserProfessionalIndex(indexes.SearchIndex, indexes.Indexable):
    userprofile = indexes.CharField(model_attr='userprofile')

    def get_model(self):
        return UserProfessional

and in the search template specify

{{ object.userprofile.zip_code }}
{{ object. bio_exp }} 

Now search for zip_code and other params and you will get back bio_exp from UserProfessional and other fields.

Hope this helps.

๐Ÿ‘คNitin Arora

Leave a comment