Created
June 17, 2019 15:21
-
-
Save zlavergne/525502634b21ebace46ee02d122cd717 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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