Source

django-tsearch2 / tsearch2 / signals.py

Full commit
from django.db.models.signals import post_save
from tsearch2 import registry


def handler(sender,  instance, **kwargs):
    """
    A convience signal that provides an update_index method for object instances,
    as well as automatic index updating. The index is stored as a tsvector column on the
    model's table. At model registry you can provide 'auto_reindex' boolean parameter to 
    control whether the index is automatically updated when save is called.
    """
    manager = getattr(sender, sender._meta.search_manager_attr)
    if sender.auto_reindex:
        manager.update_index()
    else:
        manager.update_index(pk=instance.pk)


for model in registry:
    post_save.connect(handler, sender=model)