Skip to content

Instantly share code, notes, and snippets.

@ketanbhatt
Created September 23, 2018 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketanbhatt/206ee53228a534ef0be625390fa16e4c to your computer and use it in GitHub Desktop.
Save ketanbhatt/206ee53228a534ef0be625390fa16e4c to your computer and use it in GitHub Desktop.
Django Haystack Index definition after using custom code
class MyModelIndex(AutoPrepareTextIndexMixin, CelerySearchIndex, indexes.Indexable):
model_pk = indexes.IntegerField(model_attr='pk') # This is required
text = indexes.EdgeNgramField(document=True) # This too
some_boolean = indexes.IntegerField(model_attr='some_boolean')
# Filters should map to the exact field name that the admin will access them by.
# Example: foreign keys are accessed by FKModel__id. This is for filters
rel_model = indexes.IntegerField(model_attr='rel_model__id')
document_fields = ['name', 'nickname', 'rel_model__title'] # ^_^
select_related_for_index = ['business']
def get_model(self):
return MyModel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment