I have a class defined in Python called Employees
. Its attribute id_supervisor
is the id
of the employee who is in charge of him.
One employee can be in charge of (supervise) many other employees.
This is my class:
class Employee(DeclarativeBase):
__tablename__ = 'employees'
id_ = Column('id',Integer,primary_key=True)
name = Column(Unicode(50))
id_supervisor = Column(Integer, ForeignKey('employees.id'))
#other attributes ...
What I need to do is to get the whole hierarchical structure of the company, from the boss of the company (he would have his id_supervisor
attribute set to None
or to himself) to the lowest worker of the company (he would be supervising no workers at all).
How could this be done? I have been thinking about using a recursive function, but I really don't know how to do it.
Any help would be appreciated.