def suspended_updates():
    """
    This allows you to postpone updates to all the search indexes inside of a with:

        with suspended_updates():
            model1.save()
            model2.save()
            model3.save()
            model4.delete()
    """
    if getattr(local_storage, "bulk_queue", None) is None:
        local_storage.bulk_queue = defaultdict(list)

    try:
        yield
    finally:
        for index, items in local_storage.bulk_queue.items():
            index.bulk(chain(*items))
        local_storage.bulk_queue = None
This allows you to postpone updates to all the search indexes inside of a with:

        with suspended_updates():
            model1.save()
            model2.save()
            model3.save()
            model4.delete()