def create_deletion_handler(preference):
    """
    Will generate a dynamic handler to purge related preference
    on instance deletion
    """
    def delete_related_preferences(sender, instance, *args, **kwargs):
        queryset = preference.registry.preference_model.objects\
                                      .filter(name=preference.name,
                                              section=preference.section)
        related_preferences = queryset.filter(
            raw_value=preference.serializer.serialize(instance))
        related_preferences.delete()
    return delete_related_preferences
def create_deletion_handler ( preference ) : def delete_related_preferences ( sender , instance , * args , ** kwargs ) : queryset = preference . registry . preference_model . objects . filter ( name = preference . name , section = preference . section ) related_preferences = queryset . filter ( raw_value = preference . serializer . serialize ( instance ) ) related_preferences . delete ( ) return delete_related_preferences
Will generate a dynamic handler to purge related preference
    on instance deletion