added search defaults mimicing old search behavior
This commit is contained in:
33
cookbook/migrations/0157_alter_searchpreference_trigram.py
Normal file
33
cookbook/migrations/0157_alter_searchpreference_trigram.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Generated by Django 3.2.7 on 2021-09-29 06:37
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from django.db import migrations, models
|
||||
from cookbook.models import nameSearchField
|
||||
|
||||
|
||||
def add_default_trigram(apps, schema_editor):
|
||||
with scopes_disabled():
|
||||
SearchFields = apps.get_model('cookbook', 'SearchFields')
|
||||
SearchPreference = apps.get_model('cookbook', 'SearchPreference')
|
||||
|
||||
name_field = SearchFields.objects.get(name='Name')
|
||||
|
||||
for p in SearchPreference.objects.all():
|
||||
if not p.trigram.all() and p.search == 'plain':
|
||||
p.trigram.add(name_field)
|
||||
p.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0156_searchpreference_trigram_threshold'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='searchpreference',
|
||||
name='trigram',
|
||||
field=models.ManyToManyField(blank=True, default=nameSearchField, related_name='trigram_fields', to='cookbook.SearchFields'),
|
||||
),
|
||||
migrations.RunPython(add_default_trigram),
|
||||
]
|
Reference in New Issue
Block a user