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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset