def set_encode_profiles(sender, instance, **kwargs):
    # Store the currently configured encoding profiles
    # so we can compare against them post-save
    if instance.pk:
        instance._profiles = set(list(instance.profiles.values_list('pk', flat=True)))
    else:
        instance._profiles = set(list())

    # If a new file is being uploaded that is different
    # from the existing file, set it to be re-encoded
    if hasattr(instance.file.file, 'temporary_file_path'):
        try:
            current = sender.objects.get(pk=instance.pk)
        except sender.DoesNotExist:
            pass
        else:
            current_file = os.path.join(settings.MEDIA_ROOT, current.file.name)
            new_file = os.path.join(settings.MEDIA_ROOT,
                                    instance.file.file.temporary_file_path())
            if not cmp(current_file, new_file):
                instance._reencode = True
            current.file.delete(save=False)
Binds serializers with an object.
dataset/ETHPy150Open jbittel/django-multimedia/multimedia/signals.py/set_encode_profiles--crossover with--dataset/ETHPy150Open openstack/rack/rack/api/wsgi.py/ResponseObject.__init__