1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | from haystack.sites import site
from django.db.models import signals
def add_to_search_index(sender, instance=None, **kwargs):
try:
index = site.get_index(instance.__class__)
except:
return
index.backend.update(index, [instance])
signals.post_save.connect(add_to_search_index)
def delete_from_search_index(sender, instance=None, **kwargs):
try:
index = site.get_index(instance.__class__)
except:
return
index.backend.remove(instance)
signals.post_delete.connect(delete_from_search_index)
|
More like this
- Ordered items in the database - alternative by Leonidas 5 years, 11 months ago
- AutoSlugField by callipeo 5 years, 5 months ago
- Setting distinction between development and public server by Archatas 6 years, 2 months ago
- db_dump.py - for dumpping and loading data from database by limodou 6 years, 2 months ago
- Simple file size from bytes to kb/mb/gb by bryanhelmig 3 years, 4 months ago
Comments
Don't use this snippet. Use RealTimeSearchIndex instead of SearchIndex.
#