Mercurial > public > sg101
comparison bio/search_indexes.py @ 753:ad53d929281a
For issue #62, upgrade Haystack from 1.2.7 to 2.1.0.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 03 Jan 2014 19:01:18 -0600 |
parents | ee87ea74d46b |
children | cf9918328c64 |
comparison
equal
deleted
inserted
replaced
752:95f4e7f352fd | 753:ad53d929281a |
---|---|
1 """Haystack search index for the bio application.""" | 1 """Haystack search index for the bio application.""" |
2 from haystack.indexes import * | 2 from haystack import indexes |
3 from haystack import site | |
4 from custom_search.indexes import CondQueuedSearchIndex | |
5 | 3 |
6 from bio.models import UserProfile | 4 from bio.models import UserProfile |
7 from bio.signals import profile_content_update | |
8 | 5 |
9 | 6 |
10 class UserProfileIndex(CondQueuedSearchIndex): | 7 class UserProfileIndex(indexes.SearchIndex, indexes.Indexable): |
11 text = CharField(document=True, use_template=True) | 8 text = indexes.CharField(document=True, use_template=True) |
12 author = CharField(model_attr='user') | 9 author = indexes.CharField(model_attr='user') |
13 | 10 |
14 def index_queryset(self): | 11 def get_model(self): |
12 return UserProfile | |
13 | |
14 def index_queryset(self, using=None): | |
15 return UserProfile.objects.filter(user__is_active=True) | 15 return UserProfile.objects.filter(user__is_active=True) |
16 | 16 |
17 def get_updated_field(self): | 17 def get_updated_field(self): |
18 return 'update_date' | 18 return 'update_date' |
19 | |
20 def _setup_save(self, model): | |
21 profile_content_update.connect(self.enqueue_save) | |
22 | |
23 def _teardown_save(self, model): | |
24 profile_content_update.disconnect(self.enqueue_save) | |
25 | |
26 def enqueue_save(self, sender, **kwargs): | |
27 return self.enqueue('update', sender) | |
28 | |
29 | |
30 site.register(UserProfile, UserProfileIndex) |