diff options
author | Alvin Li <liweitianux@gmail.com> | 2013-08-13 14:13:24 +0800 |
---|---|---|
committer | Alvin Li <liweitianux@gmail.com> | 2013-08-13 14:13:24 +0800 |
commit | 9636d4a6767f49384d5c386bc3f1142c88b90613 (patch) | |
tree | 3a70f6d9e4be1791d36c87cc7cbfd1d5aa2b39dd /97suifangqa/apps/indicator/search_indexes.py | |
parent | 9383d9a8a5988d071766c3d08a5c946e9c5b02ae (diff) | |
download | 97dev-9636d4a6767f49384d5c386bc3f1142c88b90613.tar.bz2 |
cloned from 'bitbucket', 2013/08/13
Diffstat (limited to '97suifangqa/apps/indicator/search_indexes.py')
-rw-r--r-- | 97suifangqa/apps/indicator/search_indexes.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/97suifangqa/apps/indicator/search_indexes.py b/97suifangqa/apps/indicator/search_indexes.py new file mode 100644 index 0000000..b7a8437 --- /dev/null +++ b/97suifangqa/apps/indicator/search_indexes.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +from haystack import indexes + +from indicator import models as im + + + +# IndicatorCategoryIndex {{{ +class IndicatorCategoryIndex(indexes.SearchIndex, indexes.Indexable): + """ + search index for 'Indicator' + """ + text = indexes.CharField(document=True, use_template=True) + addByUser = indexes.CharField(model_attr='addByUser') + + def get_model(self): + return im.IndicatorCategory + + def index_queryset(self, using=None): + """ + used when the entire index for model is updated + """ + return self.get_model().objects.all() +# }}} + + +# IndicatorIndex {{{ +class IndicatorIndex(indexes.SearchIndex, indexes.Indexable): + """ + search index for 'Indicator' + """ + text = indexes.CharField(document=True, use_template=True) + addByUser = indexes.CharField(model_attr='addByUser') + dataType = indexes.CharField(model_attr='dataType') + categories = indexes.MultiValueField() + + def get_model(self): + return im.Indicator + + def prepare_categories(self, obj): + return [c.id for c in obj.categories.all()] + + def index_queryset(self, using=None): + """ + used when the entire index for model is updated + """ + return self.get_model().objects.all() +# }}} + + + +# vim: set ts=4 sw=4 tw=0 fenc=utf-8 ft=python: |