added search defaults mimicing old search behavior

This commit is contained in:
vabene1111
2021-09-29 09:04:46 +02:00
parent 856c34a3bf
commit 12afb3eaa6
3 changed files with 49 additions and 3 deletions

View 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),
]