示例#1
0
def unregister_referenced_index(sender, **kwargs):
    """Unregister a :class:`ObjectIndex` if there isn't any references to it."""
    instance = kwargs['instance']
    
    #get the key referencing the ObjectIndex class
    fkeys = foreign_keys(instance.__class__)
    fkeys.update(many_to_many_fields(instance.__class__))
    index_key = None
    for key, details in fkeys.items() :
        if issubclass(details['class'], ObjectIndex) :
            index_key = key
            break
    
    #if found get the ObjectIndex instance
    #its reverse foreign keys and reverse many to many fields
    #then detect if some relationships remain
    #and finally delete the ObjectIndex instance
    #if it is not the case
    if index_key :
        index = getattr(instance, index_key)
        keys = reverse_foreign_keys(ObjectIndex).keys()
        keys.extend(reverse_many_to_many_fields(ObjectIndex).keys())
        for key in keys :
            count = getattr(index, key).all()
            if count :
                return
        index.delete()
示例#2
0
def get_links(cls):
    """
    Get fields materialising dependencies between 2
    classes that don't lead to a delete cascading.
    """
    dct = SortedDict()
    dct.update(many_to_many_fields(cls))
    dct.update(reverse_many_to_many_fields(cls))
    return dct