Created
September 24, 2011 01:35
-
-
Save melinath/1238826 to your computer and use it in GitHub Desktop.
Haystack 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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