Added sort_tree method to manage.py