from haystack import indexes from models import Company """ class CompanyIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) where = indexes.MultiValueField() theme = indexes.MultiValueField() tag = indexes.MultiValueField() country = indexes.CharField(model_attr='country', null=True) city = indexes.CharField(model_attr='city', null=True) def prepare_country(self, obj): if obj.country: return '%s'%obj.country.id return '' def prepare_city(self, obj): if obj.city: return '%s'%obj.city.id return '' def prepare_theme(self, obj): return [str(th.id) for th in obj.theme.filter()] def prepare_tag(self, obj): return [str(tag.id) for tag in obj.tag.filter()] def prepare_where(self, obj): country = [] city = [] if obj.country: country = [tr.name for tr in obj.country.translations.all()] if obj.city: city = [tr.name for tr in obj.city.translations.all()] return country + city def get_model(self): return Company def index_queryset(self, using=None): return self.get_model().objects.filter() """