Skip to content

Commit

Permalink
Fetch related
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Nov 13, 2024
1 parent 49815e3 commit 9e94970
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ def search(request: HttpRequest) -> HttpResponse:
# Search
# Using the 'or' operator to search for pages that contain any of the words
if search_query:
search_results = Page.objects.live().search(
search_query,
operator="or",
search_results = (
Page.objects.live()
.specific() # Get specific page types in single query
.select_related( # Fetch related fields in single query
"owner",
"content_type",
"locale",
)
.search(
search_query,
operator="or",
)
)
else:
search_results = Page.objects.none()
Expand Down

0 comments on commit 9e94970

Please sign in to comment.