class Roles(db.Model, RoleMixin): __tablename__ = "roles" # Primary key id = db.Column(db.Integer(), primary_key=True) # Columns name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) # Representation def __repr__(self): return '<id %r>' % self.id
from shared import db role_users = db.Table( 'role_users', db.Column( 'user_id', db.Integer(), db.ForeignKey('roles.id', onupdate="CASCADE", ondelete="CASCADE")), db.Column( 'role_id', db.Integer(), db.ForeignKey('users.id', onupdate="CASCADE", ondelete="CASCADE")), )
from shared import db post_comments = db.Table( 'post_comments', db.Column( 'post_id', db.Integer(), db.ForeignKey('posts.id', onupdate="CASCADE", ondelete="CASCADE")), db.Column( 'comment_id', db.Integer(), db.ForeignKey('comments.id', onupdate="CASCADE", ondelete="CASCADE")))
class Application(db.Model): __tablename__ = "application" id = db.Column( "application_id", db.Integer, primary_key=True) needs = db.Column( "needs", db.String(), nullable=False) status = db.Column( "status", db.Enum(ApplicationStatus), nullable=False) rank = db.Column( "rank", db.Enum(Rank) ) comments = db.Column( "comments", db.String(100)) applicationSeasonId = db.Column( "applicationSeasonId", db.ForeignKey("application_season.application_season_id"), nullable=False, ) applicationSeason = db.relationship( "ApplicationSeason", back_populates="applications", ) queuePlacement = db.Column( "queuePlacement", db.Integer() ) db.UniqueConstraint( 'applicationSeasonId', 'queuePlacement', name='uix_1') userid = db.Column( db.Integer, db.ForeignKey("users.userid"), nullable=False, ) user = db.relationship( "User", uselist=False, back_populates="application") partnerUsername = db.Column( "applies_with", db.String(50), nullable=True) partnerApplicationId = db.Column( db.Integer, db.ForeignKey("application.application_id")) partnerApplication = db.relationship( "Application", uselist=False, backref='partnersApplication', remote_side="Application.id", post_update=True) preferredRoom = db.Column( "preferredRoom", db.String(50) ) db.UniqueConstraint( "applicationSeasonId", "userid", name="uix" ) seatRollover = db.Column( "seatRollover", db.Boolean() ) seat_id = db.Column( db.Integer, db.ForeignKey('seats.seat_id') ) seat = db.relationship( Seat, uselist=False, back_populates="application" ) def __init__(self, status, needs, user, partnerUsername, preferredRoom, seatRollover, applicationSeason, comments, rank=Rank.OTHER): self.status = status self.user = user self.needs = needs self.comments = comments self.preferredRoom = preferredRoom self.seatRollover = seatRollover self.partnerUsername = partnerUsername self.rank = rank self.applicationSeason = applicationSeason def to_json(self, self_referred=False): applicationDict = { "id": self.id, "status": self.status.name, "comments": self.comments, "needs": self.needs, "rank": self.rank.name, "preferredRoom": self.preferredRoom, "seatRollover": self.seatRollover, "seat": self.seat.to_json(False) if self.seat else None, "user": self.user.to_json() if self.user else None, } # Do not return partnerApplication if jsoning through a partner application. if not self_referred: applicationDict["partnerApplication"] = (self.partnerApplication.to_json(self_referred=True) if self.partnerApplication else {}) applicationDict["seat"] = self.seat.to_json() if self.seat else None return applicationDict def __str__(self): return json.dumps(self.to_json()) def userEditableFields(self): return ["comments", "needs", "preferredRoom", "seatRollover", "partnerUsername"]
from shared import db post_tags = db.Table( 'post_tags', db.Column( 'post_id', db.Integer(), db.ForeignKey('posts.id', onupdate="CASCADE", ondelete="CASCADE")), db.Column('tag_id', db.Integer(), db.ForeignKey('tags.id', onupdate="CASCADE", ondelete="CASCADE")), )
# -*- coding: utf-8 -*- ''' USER MODEL ''' from flask_security import UserMixin, RoleMixin from shared import db # Define the relationship between roles and users roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('users.id')), db.Column('role_id', db.Integer(), db.ForeignKey('roles.id')) ) # Roles should include users and admins class Roles(db.Model, RoleMixin): __tablename__ = "roles" # Primary key id = db.Column(db.Integer(), primary_key=True) # Columns name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) # Representation def __repr__(self): return '<id %r>' % self.id # Use email as username class Users(db.Model, UserMixin): __tablename__ = 'users'