def register_for_indexing(app,
                          sender_class,
                          instance_to_indexee=_identity,
                          m2m=False):
    def maybe_call_method(instance, is_raw, method_name):
        """Call an (un-)indexing method on instance if appropriate."""
        obj = instance_to_indexee(instance)
        if obj is not None and not is_raw:
            getattr(obj, method_name)()

    def update(sender, instance, **kw):
        """File an add-to-index task for the indicated object."""
        maybe_call_method(instance, kw.get('raw'), 'index_later')

    def delete(sender, instance, **kw):
        """File a remove-from-index task for the indicated object."""
        maybe_call_method(instance, kw.get('raw'), 'unindex_later')

    def indexing_receiver(signal, signal_name):
        """Return a routine that registers signal handlers for indexers.

        The returned registration routine uses strong refs, makes up a
        dispatch_uid, and uses ``sender_class`` as the sender.

        """
        return receiver(
            signal,
            sender=sender_class,
            dispatch_uid='%s.%s.elastic.%s' %
                         (app, sender_class.__name__, signal_name),
            weak=False)

    if m2m:
        # This is an m2m model, so we regstier m2m_chaned and it
        # updates the existing document in the index.
        indexing_receiver(m2m_changed, 'm2m_changed')(update)

    else:
        indexing_receiver(post_save, 'post_save')(update)

        indexing_receiver(pre_delete, 'pre_delete')(
            # If it's the indexed instance that's been deleted, go ahead
            # and delete it from the index. Otherwise, we just want to
            # update whatever model it's related to.
            delete if instance_to_indexee is _identity else update)
Registers a model for signal-based live-indexing.
dataset/ETHPy150Open mozilla/kitsune/kitsune/search/models.py/register_for_indexing