Unless I’m missing something, django-haystack’s RealTimeSearchIndex cares only about post_save and post_delete. That’s generally fine, but you’re not going to have access your many-to-many relationships when an instance is prepared for indexing. Django saves instance data and many to many data in three steps:
- Instance data is saved first to ensure a primary key is ready when building relationships to and from this object.
- Next, the many-to-many field is cleared.
- Finally, the many-to-many data is saved.
Now, the post_save signal fires between steps one and two. This means when post_save is fired, your many-to-many data hasn’t been saved, and is not available on the model instance Haystack has ahold of.
The trick here is to connect each many-to-many field on the model to Django’s m2m_changed signal and selectively listen to the actions it passes along when fired. m2m_changed is pretty chatty, so we only want to listen for a select few scenarios: really, anything “post”.
Here’s a quick solution I’ve put together using the _setup_save hook (and _teardown_save) the framework provides.
Haystack is a great option for indexing your site’s content with a number of search backends. It makes total sense to leave this kind of functionality out, and the hooks built in for extensions like this are perfect.
By the way, if I’ve missed something obvious, please let me know!




