from django.core.management.base import BaseCommand, CommandError
from django.contrib.postgres.search import SearchVector, SearchQuery, SearchRank
from django.contrib.postgres.aggregates import StringAgg
#from polls.models import Question as Poll
#import  json
#from pprint import pprint
from catalog.models import News


class Command(BaseCommand):
	help = 'Update search vectors'

#    def add_arguments(self, parser):
#        parser.add_argument('filename', nargs=1, type=str)

	def handle(self, *args, **options):
		vector=SearchVector('text')
		for news in News.objects.annotate(document=vector):
			news.search_vector = news.document
			news.save(update_fields=['search_vector'])
