Skip to content

Instantly share code, notes, and snippets.

@GrayHatter
Created November 23, 2018 03:11
Show Gist options
  • Save GrayHatter/234461a9cd302594f6f14598dda33be9 to your computer and use it in GitHub Desktop.
Save GrayHatter/234461a9cd302594f6f14598dda33be9 to your computer and use it in GitHub Desktop.
class BaseGroup(Base):
# ...
parent_id = Column(Integer, ForeignKey('base_groups.id'))
parent = relationship('BaseGroup',
foreign_keys='BaseGroup.id',
primaryjoin='BaseGroup.parent_id == BaseGroup.id',
uselist=False)
child_groups = relationship('BaseGroup',
foreign_keys='BaseGroup.parent_id',
primaryjoin='BaseGroup.id == BaseGroup.parent_id',
uselist=True)
roster = relationship("BaseGroupRoster",
order_by="BaseGroupRoster.position",
collection_class=ordering_list('position', count_from=1),
lazy='joined')
@hybrid_property
def sub_roster(self):
roster = self.roster
for each in self.child_groups:
print(each.name)
roster += each.sub_roster
return roster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment