blob: c158a2588b80042c4490a7b7764fcc12599953d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from django.core.management.base import BaseCommand
import django.apps
class Command(BaseCommand):
help = "./manage.py update_search_vectors\n\n"\
"Update full texte search vectors."
def handle(self, *args, **options):
for model in django.apps.apps.get_models():
if hasattr(model, "update_search_vector") and \
(getattr(model, "BASE_SEARCH_VECTORS", None) or
getattr(model, "INT_SEARCH_VECTORS", None) or
getattr(model, "M2M_SEARCH_VECTORS", None) or
getattr(model, "PARENT_SEARCH_VECTORS", None)):
self.stdout.write("\n* update {}".format(model))
total = model.objects.count()
for idx, item in enumerate(model.objects.all()):
sys.stdout.write("\r{}/{} ".format(idx + 1, total))
sys.stdout.flush()
try:
item.update_search_vector()
except:
pass
self.stdout.write("\n")
|