mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-01 20:14:55 +00:00
add an example of indexing related model fields
This commit is contained in:
parent
0f7104ce40
commit
bece8ca86e
1 changed files with 15 additions and 0 deletions
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue