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.
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
11 class EntryIndex(indexes.SearchIndex, indexes.Indexable):
12 text = indexes.CharField(
14 model_attr=localize_field('body', settings.LANGUAGE_CODE),
16 date = indexes.DateTimeField(indexed=True, model_attr="date")
17 author = indexes.CharField(model_attr="author")
22 def index_queryset(self):
23 """Used when the entire index for model is updated."""
24 return self.get_model().objects.all()
27 add_translatable_index(EntryIndex, {
28 'title': indexes.CharField(null=True),
29 'lead': indexes.CharField(null=True),
32 add_translatable_index(EntryIndex, {
33 'title': indexes.CharField(null=True),
34 'lead': indexes.CharField(null=True),
35 'body': indexes.CharField(null=True)
37 (lang for lang in settings.LANGUAGES if lang[0] != settings.LANGUAGE_CODE)