working proof of concept

This commit is contained in:
smilerz
2021-04-09 12:46:07 -05:00
parent 913e896906
commit d71f8ae006
7 changed files with 123 additions and 12 deletions

25
cookbook/signals.py Normal file
View File

@ -0,0 +1,25 @@
from django.contrib.postgres.search import SearchVector
from django.db.models.signals import post_save
from django.dispatch import receiver
from cookbook.models import Recipe
@receiver(post_save, sender=Recipe)
def update_recipe_search_vector(sender, instance=None, created=False, **kwargs):
if not instance:
return
if hasattr(instance, '_dirty'):
return
instance.search_vector = (
SearchVector('name', weight='A', config='english')
+ SearchVector('description', weight='B', config='english')
)
try:
instance._dirty = True
instance.save()
finally:
del instance._dirty