snipt/snipts/search_indexes.py

20 lines
649 B
Python
Raw Normal View History

2012-04-16 21:42:01 -07:00
import datetime
2015-07-24 18:39:25 -07:00
2012-04-16 21:42:01 -07:00
from haystack import indexes
from snipts.models import Snipt
2013-01-20 10:42:18 -08:00
class SniptIndex(indexes.SearchIndex, indexes.Indexable):
2012-04-16 21:42:01 -07:00
text = indexes.CharField(document=True, use_template=True)
2019-01-23 15:52:55 -08:00
author = indexes.CharField(model_attr="user")
pub_date = indexes.DateTimeField(model_attr="created")
public = indexes.BooleanField(model_attr="public")
typ = indexes.CharField(model_attr="lexer")
2012-04-16 21:42:01 -07:00
def get_model(self):
return Snipt
2013-03-24 15:41:57 -07:00
def index_queryset(self, **kwargs):
2012-04-16 21:42:01 -07:00
"""Used when the entire index for model is updated."""
2019-01-23 15:52:55 -08:00
return self.get_model().objects.filter(created__lte=datetime.datetime.now())