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
- Removing old ImageFields and FileFields when updating through admin by alejandro.alonso 2 weeks, 4 days ago
- REMOVE IMAGEFIELD ATTACHMENT IN DJANGO by timonweb 2 weeks, 1 day ago
- Model Hooks by jakecr 2 years, 4 months ago
- Automatic CRUD urls from your models... by codigodaniel 1 year, 4 months ago
- FileField / ImageField with a delete checkbox by tomZ 4 years, 6 months ago
Comments
Don't use this snippet. Use RealTimeSearchIndex instead of SearchIndex.
#