class Organization(db.Model): __tablename__ = 'organizations' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(1023), nullable=False) top_level_message_id = db.Column( db.Integer, db.ForeignKey('top_level_messages.id'), ) top_level_message = db.relationship( 'TopLevelMessage', uselist=False, back_populates='organization', cascade='save-update, merge, delete', ) users = db.relationship( 'OrganizationUser', uselist=True, back_populates='organization', ) def __repr__(self): return "<Organization(name='%s')>" % self.name
class TopLevelMessage(db.Model): __tablename__ = 'top_level_messages' id = db.Column(db.Integer, primary_key=True) header_content = db.Column(db.UnicodeText) organization = db.relationship( 'Organization', uselist=False, back_populates='top_level_message', ) top_level_options = db.relationship( 'TopLevelOption', uselist=True, back_populates='top_level_message', cascade='save-update, merge, delete', )
class TopLevelOption(db.Model): __tablename__ = 'top_level_options' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Unicode(255), nullable=False) content = db.Column(db.UnicodeText) position = db.Column(db.Integer, nullable=False) top_level_message_id = db.Column( db.Integer, db.ForeignKey('top_level_messages.id'), nullable=False, ) top_level_message = db.relationship( 'TopLevelMessage', back_populates='top_level_options', ) secondary_options = db.relationship( 'SecondaryOption', uselist=True, back_populates='top_level_option', cascade='save-update, merge, delete', )
class SecondaryOption(db.Model): __tablename__ = 'secondary_option' id = db.Column(db.Integer, primary_key=True) content = db.Column(db.UnicodeText) position = db.Column(db.Integer, nullable=False) top_level_option_id = db.Column( db.Integer, db.ForeignKey('top_level_options.id'), nullable=False, ) top_level_option = db.relationship( 'TopLevelOption', back_populates='secondary_options', )
class OrganizationUser(db.Model): __tablename__ = 'organization_users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.Unicode(255), nullable=False) email = db.Column(db.Unicode(255), nullable=False) password = db.deferred( db.Column('password_hashed', PasswordType, nullable=False)) organization_id = db.Column( db.Integer, db.ForeignKey('organizations.id'), nullable=False, ) organization = db.relationship( 'Organization', uselist=False, back_populates='users', )