def get(self): departmentlist = [] for department in DepartmentModel.list(): children = [] for child in department.children: children.append({ 'id': child.id, 'parent_id': child.parent_id, 'name': child.name, 'description': child.description, }) model = { 'id': department.id, 'parent_id': department.parent_id, 'name': department.name, 'description': department.description, 'children': children } departmentlist.append(model) return jsonify({'departments': departmentlist})