import datetime
from haystack import indexes
from blog.models import Note
from celery_haystack.indexes import CelerySearchIndex


class NoteIndex(CelerySearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    # text = indexes.CharField(document=True, )
    author = indexes.CharField(model_attr='user')
    pub_date = indexes.DateTimeField(model_attr='pub_date')

    def get_model(self):
        return Note

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        rs = self.get_model().objects.filter(
            pub_date__lte=datetime.datetime.now())
        return rs
