48d0a1ca7781ba2da644745271413c9a0f0efc99
[prawokultury.git] / events / search_indexes.py
1 import datetime
2 from django.conf import settings
3 from haystack import indexes
4 from fnpdjango.utils.models.translation import add_translatable_index
5 from events.models import Event
6
7
8 class EventIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
9     def get_model(self):
10         return Event
11
12     def index_queryset(self):
13         """Used when the entire index for model is updated."""
14         return self.get_model().objects.all()
15
16
17 add_translatable_index(EventIndex, {
18 # Haystack needs a main field to be the same across all indexes
19 # so we treat title of the event as this main content, named 'body'
20    'body': indexes.CharField(model_attr='title', null=True),
21    'organizer': indexes.CharField(null=True),
22    'place': indexes.CharField(null=True)
23    })
24
25
26 getattr(EventIndex, "body_%s" % settings.LANGUAGE_CODE).document = True