Reputation: 155
Quick question on wagtail's main search at the top of the left sidebar beneath the logo. By default that search box searches pages, images, documents, users.
Two questions: Is there a way to modify that search scope so it also includes modelAdmin models? Is there a way to remove pages from the search query list so it only searches images, documents, users?
I can't seem to find anything in the docs about it. I know you can search modelAdmin models once on the model admin list view, I have that working. I was just looking for a way to extend that search to be included on the main sidebar search as well.
Any direction you can provide would be much appreciated.
Upvotes: 0
Views: 1403
Reputation: 5196
The admin search area does show multiple items, such as pages, images, documents etc.
However, this page only searches page
models, when you click the other models (e.g. images), it will take you to the images search page, it will also append the query param q
based on any existing search.
So just to clarify, this page only searches pages and to search for other items, it takes you elsewhere in the Wagtail admin.
Hopefully the below answers your specific scenario questions.
admin/pages
search scope or resultssearch
view function here https://github.com/wagtail/wagtail/blob/master/wagtail/admin/views/pages.py#L958admin/pages/search/
page to your custom view.register_admin_search_area
hook, it will add (in a custom order) an item next to the 'other searches' textwagtail/admin/templates/wagtailadmin/shared/search_other.html
with an override and then filter the resultsadmin_search_areas
you can see the code here - https://github.com/wagtail/wagtail/blob/master/wagtail/admin/search.py#L102register_admin_search_area
hookThis basically uses the documentation example but gives you a rough idea of how to go to a specific ModelAdmin
index view using this feature. Note: this does not search ALL ModelAdmin models, only one specific one.
You can always make a custom search page for searching all models at once though.
from wagtail.core import hooks
from wagtail.admin.search import SearchArea
# ...
@hooks.register('register_admin_search_area')
def register_model_admin_search_area():
# PeopleModelAdmin is a ModelAdmin also in the same hooks file
index_url = PeopleModelAdmin().url_helper.index_url
return SearchArea(
'People ModelAdmin',
index_url,
classnames='icon icon-user',
order=10000
)
@hooks.register('register_admin_search_area')
def register_snippets_search_area():
url = reverse('wagtailsnippets:list', args=('base', 'people'))
return SearchArea(
'People Snippets',
url,
classnames='icon icon-user',
order=10000
)
Upvotes: 2