You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.2 KiB

from haystack import indexes
from models import Exposition
class ExpositionIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
where = indexes.MultiValueField()
data_begin = indexes.DateField(model_attr='data_begin')
data_end = indexes.DateField(model_attr='data_end')
theme = indexes.MultiValueField()
tag = indexes.MultiValueField()
country_id = indexes.IntegerField()
city_id = indexes.IntegerField()
area_id = indexes.IntegerField()
def prepare_area_id(self, obj):
return obj.country.area.id
def prepare_country_id(self, obj):
return obj.country.id
def prepare_city_id(self, obj):
return obj.city.id
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_where(self, obj):
country = [tr.name for tr in obj.country.translations.all()]
city = [tr.name for tr in obj.city.translations.all()]
return country + city
def get_model(self):
return Exposition
def index_queryset(self, using=None):
return self.get_model().objects.filter(is_published=True)