diff --git a/corepos/db/office_op/model.py b/corepos/db/office_op/model.py index 5b494c7..330e8d1 100644 --- a/corepos/db/office_op/model.py +++ b/corepos/db/office_op/model.py @@ -74,6 +74,38 @@ class Parameter(Base): return "{}-{} {}".format(self.store_id, self.lane_id, self.param_key) +class SuperDepartment(Base): + """ + Represents a "super" (parent/child) department mapping. + """ + __tablename__ = 'superdepts' + __table_args__ = ( + sa.ForeignKeyConstraint(['superID'], ['departments.dept_no']), + sa.ForeignKeyConstraint(['dept_ID'], ['departments.dept_no']), + ) + + parent_id = sa.Column('superID', sa.Integer(), primary_key=True, autoincrement=False, nullable=False) + parent = orm.relationship( + 'Department', + foreign_keys=[parent_id], + doc=""" + Reference to the parent department for this mapping. + """, + backref=orm.backref('_super_children')) + + child_id = sa.Column('dept_ID', sa.Integer(), primary_key=True, autoincrement=False, nullable=False) + child = orm.relationship( + 'Department', + foreign_keys=[child_id], + doc=""" + Reference to the child department for this mapping. + """, + backref=orm.backref('_super_parent', uselist=False)) + + def __str__(self): + return "{} / {}".format(self.parent, self.child) + + class Department(Base): """ Represents a department within the organization.