diff --git a/.gitignore b/.gitignore index 218eb763..4e0807f2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ doc/html data/ static/ sith/settings_custom.py +sith/whoosh_index/ diff --git a/core/models.py b/core/models.py index 560d87a3..efc18803 100644 --- a/core/models.py +++ b/core/models.py @@ -190,7 +190,7 @@ class User(AbstractBaseUser): return reverse('core:user_profile', kwargs={'user_id': self.pk}) def __str__(self): - return self.username + return self.get_display_name() def to_dict(self): return self.__dict__ diff --git a/core/search_indexes.py b/core/search_indexes.py new file mode 100644 index 00000000..053e9c74 --- /dev/null +++ b/core/search_indexes.py @@ -0,0 +1,19 @@ +from haystack import indexes + +from core.models import User + + +class UserIndex(indexes.SearchIndex, indexes.Indexable): + text = indexes.CharField(document=True, use_template=True) + + def get_model(self): + return User + + def index_queryset(self, using=None): + """Used when the entire index for model is updated.""" + return self.get_model().objects.all() + + def prepare(self, obj): + ret = super(UserIndex, self).prepare(obj) + print(ret) + return ret diff --git a/core/templates/search/indexes/core/user_text.txt b/core/templates/search/indexes/core/user_text.txt new file mode 100644 index 00000000..cdf57bc2 --- /dev/null +++ b/core/templates/search/indexes/core/user_text.txt @@ -0,0 +1,3 @@ +{{ object.get_display_name|safe }} +{{ object.get_display_name|safe|slugify }} +{{ object.get_display_name|safe|slugify|cut:"-" }} diff --git a/requirements.txt b/requirements.txt index 057a8460..e723a6a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,5 +9,7 @@ djangorestframework django-phonenumber-field django-ajax-selects reportlab +django-haystack +whoosh # mysqlclient diff --git a/sith/settings.py b/sith/settings.py index d33c939e..549d739f 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = ( 'django_jinja', 'rest_framework', 'ajax_select', + 'haystack', 'core', 'club', 'subscription', @@ -142,6 +143,13 @@ TEMPLATES = [ }, ] +HAYSTACK_CONNECTIONS = { + 'default': { + 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', + 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'), + }, + } + WSGI_APPLICATION = 'sith.wsgi.application'