Created
September 23, 2018 03:11
-
-
Save ketanbhatt/206ee53228a534ef0be625390fa16e4c to your computer and use it in GitHub Desktop.
Django Haystack Index definition after using custom code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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