Skip to content

Instantly share code, notes, and snippets.

@melinath
Created September 24, 2011 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melinath/1238826 to your computer and use it in GitHub Desktop.
Save melinath/1238826 to your computer and use it in GitHub Desktop.
Haystack 2
from django.db import Count
from haystack import indexes
from learnit.models import Course
class CourseIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.IntegerField(model_attr="user_id")
tags = indexes.CharField(model_attr="tags")
# slide_count is set during index_queryset.
slide_count = indexes.IntegerField(model_attr="slide_count")
def get_model(self):
return Course
def index_queryset(self):
return self.get_model().objects.annotate(slide_count=Count('slides'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment