Skip to content

Instantly share code, notes, and snippets.

@nitely
Created January 31, 2016 17:07
Show Gist options
  • Save nitely/3a39d6eb6dd0196ff9ae to your computer and use it in GitHub Desktop.
Save nitely/3a39d6eb6dd0196ff9ae to your computer and use it in GitHub Desktop.
Haystack extend index
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class ChildAppConfig(AppConfig):
name = 'child_app'
verbose_name = "child app"
label = 'child_app'
def ready(self):
from main_app.search_hooks import MainAppSearchHook
from .search import ChildAppIndex
MainAppSearchHook.register(ChildAppIndex)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from haystack import indexes
class ChildAppIndex(object):
body = indexes.CharField(model_attr='body')
from hooks.haystackhook import HaystackHook
MainAppSearchHook = HaystackHook()
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from haystack import indexes
from .models import MainApp
from .search_hooks import MainAppSearchHook
class MainAppIndexBase(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
def get_model(self):
return MainApp
MainAppIndex = MainAppSearchHook.build_search_index(MainAppIndexBase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment