import sys from django.core.management.base import BaseCommand from chimere import models class Command(BaseCommand): help = "Update internal search engine" def handle(self, *args, **options): for model in [models.Marker, models.Route, models.Polygon]: sys.stdout.write("* {}\n".format(model)) changed = 0 q = model.objects total = q.count() for idx, item in enumerate(q.all()): sys.stdout.write("{}/{}\r".format(idx + 1, total)) sys.stdout.flush() changed += 1 if item.update_search_vector() else 0 print("{} item(s) updated".format(changed))