1 from django.db import models
2 from django.contrib.postgres.search import SearchVector, SearchVectorField
3 from search.utils import build_search_vector
6 class Snippet(models.Model):
7 book = models.ForeignKey('Book', models.CASCADE)
8 sec = models.IntegerField()
11 text = models.TextField()
12 search_vector = SearchVectorField()
14 def save(self, *args, **kwargs):
15 super().save(*args, **kwargs)
16 if not self.search_vector:
20 self.search_vector = build_search_vector('text')
25 cls.objects.all().update(search_vector = build_search_vector('text'))