fix haystack compatibility
[django-migdal.git] / migdal / search_indexes.py
1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django.conf import settings
6 from haystack import indexes
7 from fnpdjango.utils.models.translation import add_translatable_index, localize_field
8 from migdal.models import Entry
9
10
11 class EntryIndex(indexes.SearchIndex, indexes.Indexable):
12     text = indexes.CharField(
13         null=True,
14         model_attr=localize_field('body', settings.LANGUAGE_CODE),
15         document=True)
16     date = indexes.DateTimeField(indexed=True, model_attr="date")
17     author = indexes.CharField(model_attr="author")
18
19     def get_model(self):
20         return Entry
21
22     def index_queryset(self, using=None):
23         """Used when the entire index for model is updated."""
24         return self.get_model().objects.all()
25
26
27 add_translatable_index(EntryIndex, {
28     'title': indexes.CharField(null=True),
29     'lead': indexes.CharField(null=True),
30     })
31
32 add_translatable_index(EntryIndex, {
33     'title': indexes.CharField(null=True),
34     'lead': indexes.CharField(null=True),
35     'body': indexes.CharField(null=True)
36     }, 
37     (lang for lang in settings.LANGUAGES if lang[0] != settings.LANGUAGE_CODE)
38 )