search_indexes.py 542 B

12345678910111213141516
  1. from .models import Media
  2. import datetime
  3. from haystack import indexes
  4. class MediaIndex(indexes.SearchIndex, indexes.Indexable):
  5. text = indexes.CharField(document=True, use_template=True)
  6. author = indexes.CharField(model_attr='user')
  7. pub_date = indexes.DateTimeField(model_attr='pub_date')
  8. def get_model(self):
  9. return Media
  10. def index_queryset(self, using=None):
  11. """Used when the entire index for model is updated."""
  12. return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())