Skip to content
kirknorthrop edited this page Feb 14, 2013 · 3 revisions

django-watson comes with a template tag library called watson. You can include this template tag library in your templates with the following code:

{% load watson %}

This library contains the following template tags and filters:

Tag: search_results

Renders a list of search results in a page. If the project is using Django 1.4 or above, the object of each search entry will be prefetched using prefetch_related. The results will be rendered using the "watson/includes/search_results.html" template.

Usage

{% search_results search_entry_list %}

Context variables

  • search_entry_list - A QuerySet of SearchEntry.
  • query - The query string passed to the search view.

Tag: search_result_item

Renders a single search result. The results will be rendered using a template whose name corresponds to the type of the object referenced by the search entry. The template will be chosen according the to following naming scheme:

(
    "watson/includes/search_result_{app_label}_{model_name}.html",
    "watson/includes/search_result_{app_label}.html",
    "watson/includes/search_result_item.html",
)

The template tag is useful for rendering different formatting depending on the type of the search entry.

Usage

{% search_result_item search_entry %}

Context variables

  • result - The SearchEntry instance.
  • obj - The model instance referenced by the search entry.
  • query - The query string passed to the search view.