Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wagtail indexing: Exclude some content or use queryset?

Tags:

django

wagtail

In Wagtail's documentation on ElasticSearch indexing, it seems that all instances of a given model are added to the index. But I'd like to exclude some (many) rows from being indexed, either by creating a QuerySet or by being able to set an exclude param of some kind (QuerySet would be better).

Is there any way to do this? Or do I need to index WT models from outside of Wagtail?

like image 705
shacker Avatar asked Dec 24 '22 20:12

shacker


1 Answers

You can define a get_indexed_objects method on the model class, returning a queryset of items to be indexed:

@classmethod
def get_indexed_objects(cls):
    return cls.objects.filter(live=True)
like image 113
gasman Avatar answered Dec 26 '22 08:12

gasman