Skip to content

Instantly share code, notes, and snippets.

@zlavergne
Created June 17, 2019 15:21
Show Gist options
  • Save zlavergne/525502634b21ebace46ee02d122cd717 to your computer and use it in GitHub Desktop.
Save zlavergne/525502634b21ebace46ee02d122cd717 to your computer and use it in GitHub Desktop.
# Secondary table defining many-to-many relationship between organisations and admins
organisation_admins = db.Table(
'organisation_admins',
db.metadata,
db.Column('organisation_id', db.Integer, db.ForeignKey('organisations.id'), nullable=False),
db.Column('user_id', db.BigInteger, db.ForeignKey('users.id'), nullable=False)
)
class Organisation(db.Model):
""" Describes an Organisation """
__tablename__ = 'organisations'
# Columns
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(512), nullable=False, unique=True)
logo = db.Column(db.String) # URL of a logo
url = db.Column(db.String)
visibility = db.Column(db.Integer, default=OrganisationVisibility.PUBLIC.value, nullable=False)
admins = db.relationship(
User,
secondary=organisation_admins,
backref='organisations'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment