# -*- coding: utf-8 -*- from haystack import indexes class ExpoSearchMixin(object): """ """ def prepare_where(self, obj): if obj.country: country = [tr.name for tr in obj.country.translations.all()] else: country = '' if obj.city: city = [tr.name for tr in obj.city.translations.all()] else: city = '' return country + city def prepare_content_auto(self, obj): """ object must have get_index_text method which generate text for searching """ return obj.get_index_text() def prepare_area_id(self, obj): if obj.country: return obj.country.area.id return None def prepare_country_id(self, obj): if obj.country: return obj.country.id return None def prepare_city_id(self, obj): if obj.city: return obj.city.id return None def prepare_theme(self, obj): return [th.id for th in obj.theme.filter()] def prepare_tag(self, obj): return [th.id for th in obj.tag.filter()] def prepare_url(self, obj): return obj.get_permanent_url() def prepare_name_en(self, obj): try: return obj.translations.get(language_code = 'en').name except: return '' def prepare_name_ru(self, obj): try: return obj.translations.get(language_code = 'ru').name except: return ''