Better element deletion
An element should delete its dependencies before deleting himself, helping the DB to solve its dependencies (this is a huge speedup).
Something like this seems to work:
def rm(e):
children = Element.objects.get_descending(e.id)
ids = children.values_list('id', flat=True)
Classification.objects.filter(element_id__in=ids).delete()
MetaData.objects.filter(element_id__in=ids).delete()
ElementPath.objects.filter(element_id__in=ids).delete()
children.delete()
ElementPath.objects.filter(element_id=e.id).delete()
e.delete()
Edited by Bastien Abadie