Slide 17
Slide 17 text
Python in the data model
Abstracting many-to-many relationships
class Thread(MailSyncBase, HasPublicID, HasRevisions):
tags = association_proxy(
'tagitems', 'tag',
creator=lambda tag: TagItem(tag=tag))
class TagItem(MailSyncBase):
"""Mapping between user tags and threads."""
thread_id = Column(Integer,
ForeignKey(Thread.id,
ondelete='CASCADE'),
nullable=False)
tag_id = Column(Integer, ForeignKey(Tag.id,
ondelete='CASCADE'),
nullable=False)
tag = relationship(Tag, backref='tagitems',
cascade='all, delete-orphan',
lazy='dynamic'))