官术网_书友最值得收藏!

  • Django 2 by Example
  • Antonio Melé
  • 78字
  • 2021-06-25 21:19:07

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.

主站蜘蛛池模板: 兰溪市| 新竹市| 福建省| 陆川县| 临洮县| 隆尧县| 随州市| 封丘县| 东山县| 巢湖市| 阳曲县| 隆林| 镇康县| 汉源县| 县级市| 巴楚县| 浦北县| 广饶县| 太谷县| 利川市| 庆阳市| 将乐县| 北京市| 青海省| 池州市| 高邑县| 雷波县| 玉田县| 康平县| 西华县| 长武县| 克什克腾旗| 丘北县| 葵青区| 抚宁县| 新乐市| 稷山县| 随州市| 年辖:市辖区| 祁门县| 天等县|