mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
working proof of concept
This commit is contained in:
37
cookbook/migrations/0119_auto_20210407_1828.py
Normal file
37
cookbook/migrations/0119_auto_20210407_1828.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Generated by Django 3.1.7 on 2021-04-07 20:00
|
||||
|
||||
from django.contrib.postgres.indexes import GinIndex
|
||||
from django.contrib.postgres.search import SearchVectorField, SearchVector
|
||||
from django.db import migrations
|
||||
from django_scopes import scopes_disabled
|
||||
from cookbook.models import Recipe
|
||||
|
||||
|
||||
def set_default_search_vector(apps, schema_editor):
|
||||
with scopes_disabled():
|
||||
search_vector = (
|
||||
SearchVector('name', weight='A')
|
||||
+ SearchVector('description', weight='B'))
|
||||
Recipe.objects.all().update(search_vector=search_vector)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0118_auto_20210406_1805'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='recipe',
|
||||
name='search_vector',
|
||||
field=SearchVectorField(null=True),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='recipe',
|
||||
index=GinIndex(fields=['search_vector'], name='cookbook_re_search__404e46_gin'),
|
||||
),
|
||||
migrations.RunPython(
|
||||
set_default_search_vector
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user