add an example of indexing related model fields

This commit is contained in:
Eric Drechsel 2015-01-27 14:38:24 -08:00
parent 0f7104ce40
commit bece8ca86e

View file

@ -154,6 +154,21 @@ One use for this is indexing ``get_*_display`` methods Django creates automatica
index.FilterField('is_private'),
)
Callables also provide a way to index fields from related models. In the example from :ref:`inline_panels`, to index each BookPage by the titles of its related_links:
.. code-block:: python
class BookPage(Page):
...
def get_related_link_titles(self):
# Get list of titles and concatenate them
return '\n'.join(self.related_links.values_list('text', flat=True))
search_fields = Page.search_fields + [
...
index.SearchField('get_related_link_titles'),
]
.. _wagtailsearch_indexing_models: