def encode_profiles_changed(sender, instance, action, **kwargs):
    if action in ['post_add']:
        if not hasattr(instance, '_profiles'):
            return

        added_profiles = list(kwargs['pk_set'].difference(instance._profiles))
        if added_profiles:
            instance.encode(profiles=added_profiles)
        elif hasattr(instance, '_reencode'):
            instance.encode()

        removed_profiles = list(instance._profiles.difference(kwargs['pk_set']))
        if removed_profiles:
            from .models import RemoteStorage
            from .tasks import delete_media
            for profile_id in removed_profiles:
                try:
                    storage = RemoteStorage.objects.get(media=instance,
                                                        profile_id=profile_id)
                except RemoteStorage.DoesNotExist:
                    pass
                else:
                    delete_media.delay(storage.id)
Handle changes in associated encoding profiles.
dataset/ETHPy150Open jbittel/django-multimedia/multimedia/signals.py/encode_profiles_changed