Django 2 by Example
上QQ阅读APP看书,第一时间看更新

Simple search lookups

Edit the settings.py file of your project and add django.contrib.postgres to the INSTALLED_APPS setting, as follows:

INSTALLED_APPS = [
# ...
'django.contrib.postgres',
]

Now, you can search against a single field using the search QuerySet lookup, like this:

from blog.models import Post
Post.objects.filter(body__search='django')

This query uses PostgreSQL to create a search vector for the body field and a search query from the term django. Results are obtained by matching the query with the vector.