Commits

Sergey Maranchuk committed 40d60a1

update django-haystack to 2.0 version

Comments (0)

Files changed (4)

-eac3a44a3f0169ee7d3414a5d90df90fc425dc78 projects
+b87e3b36bd5568fd1337a5bde8f2a75d021ca43e projects

djangobb_forum/search_indexes.py

-from haystack.indexes import *
-from haystack import site
+from django.utils.timezone import now 
+from haystack import indexes
 
-import djangobb_forum.models as models
-
-class PostIndex(RealTimeSearchIndex):
-    text = CharField(document=True, use_template=True)
-    author = CharField(model_attr='user')
-    created = DateTimeField(model_attr='created')
-    topic = CharField(model_attr='topic')
-    category = CharField(model_attr='topic__forum__category__name')
-    forum = IntegerField(model_attr='topic__forum__pk')
-
-site.register(models.Post, PostIndex)
+from djangobb_forum.models import Post
+ 
+ 
+class PostIndex(indexes.SearchIndex, indexes.Indexable):
+	text = indexes.CharField(document=True, use_template=True)
+	author = indexes.CharField(model_attr='user')
+	created = indexes.DateTimeField(model_attr='created')
+	topic = indexes.CharField(model_attr='topic')
+	category = indexes.CharField(model_attr='topic__forum__category__name')
+	forum = indexes.IntegerField(model_attr='topic__forum__pk')
+ 
+	def get_model(self):
+		return Post
+ 
+	def index_queryset(self, using=None):
+		# TODO: reindex updated Posts
+		return self.get_model().objects.filter(created__lte=now())

extras/requirements.txt

 Django==1.5.1
 PIL>=1.1.7
-django-haystack==1.2.7
+django-haystack==2.0
 south
 pygments
 postmarkup
     install_requires=[
             'django==1.5.1',
             'pil>=1.1.7',
-            'django-haystack==1.2.7',
+            'django-haystack==2.0',
             'django-pagination',
             'south',
             'postmarkup',