Beispiel #1
0
class User(db.Model, UserMixin):
    __tablename__ = 'user'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    roomNumber = db.Column(db.String(20))
    year = db.Column(db.Integer, nullable=False)
    points = db.Column(db.Integer, nullable=False)

    email = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(200), nullable=False)

    # Foreign key constraints (only can have one)
    gender_id = db.Column(db.Integer,
                          db.ForeignKey('gender.id'),
                          nullable=False)
    preference_id = db.Column(db.Integer, db.ForeignKey('jerseyNumber.id'))
    jerseyNumber_id = db.Column(db.Integer, db.ForeignKey('jerseyNumber.id'))

    # Relationships
    gender = db.relationship('Gender', back_populates="User")
    choice = db.relationship('Choice', backref='user', lazy=True)
    sports = db.relationship('Sport', secondary='userSports', lazy=True)
    jerseyNumber = db.relationship('JerseyNumber',
                                   foreign_keys=[preference_id],
                                   backref='users',
                                   lazy=True)
    preference = db.relationship('JerseyNumber',
                                 foreign_keys=[preference_id],
                                 backref='users_preference',
                                 lazy=True)
Beispiel #2
0
class UserSports(db.Model):
    __tablename__ = 'userSports'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)

    # foreign key constraints
    sport_id = db.Column(db.Integer, db.ForeignKey('sport.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
Beispiel #3
0
class FlaskUserRoles(db.Model):
    __tablename__ = 'flaskUserRoles'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer(),
                        db.ForeignKey('flaskUser.id', ondelete='CASCADE'))
    role_id = db.Column(db.Integer(),
                        db.ForeignKey('role.id', ondelete='CASCADE'))
Beispiel #4
0
class Admin(db.Model):
    __tablename__ = 'admin'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)

    # foreign key constraints
    flaskUser_id = db.Column(db.Integer,
                             db.ForeignKey('flaskUser.id'),
                             nullable=False)

    # Relationships
    flaskUser = db.relationship('FlaskUser', backref='admins')
Beispiel #5
0
class Sport(db.Model):
    __tablename__ = 'sport'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    sportName = db.Column(db.String(100), nullable=False)

    #foreign key constraints
    gender_id = db.Column(db.Integer,
                          db.ForeignKey('gender.id'),
                          nullable=False)

    # relationships
    Users = db.relationship('User', secondary='userSports')
    Gender = db.relationship('Gender', backref="Sport")
Beispiel #6
0
class Choice(db.Model):
    __tablename__ = 'choice'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    submitDatetime = db.Column(db.DateTime, nullable=False)
    firstChoice = db.Column(db.Integer, nullable=False)
    secondChoice = db.Column(db.Integer, nullable=False)
    thirdChoice = db.Column(db.Integer, nullable=False)
    fourthChoice = db.Column(db.Integer, nullable=False)
    fifthChoice = db.Column(db.Integer, nullable=False)

    #foreign key constraint
    # roomNumber = db.Column(db.String(20), db.ForeignKey('user.roomNumber'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
Beispiel #7
0
class JerseyNumber(db.Model):
    __tablename__ = 'jerseyNumber'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    number = db.Column(db.Integer, nullable=False)
    isTaken = db.Column(db.Boolean, default=False, nullable=False)

    # foreign key constraint
    gender_id = db.Column(db.Integer,
                          db.ForeignKey('gender.id'),
                          nullable=False)

    # relationship
    gender = db.relationship('Gender', back_populates="JerseyNumber")
Beispiel #8
0
class Choice(db.Model):
    __tablename__ = 'choice'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    submitDatetime = db.Column(db.DateTime, nullable=False)
    firstChoice = db.Column(db.Integer, nullable=False)
    secondChoice = db.Column(db.Integer, nullable=False)
    thirdChoice = db.Column(db.Integer, nullable=False)
    fourthChoice = db.Column(db.Integer, nullable=False)
    fifthChoice = db.Column(db.Integer, nullable=False)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    user = db.relationship('User', back_populates='choice', lazy=True)
Beispiel #9
0
class User(db.Model):
    __tablename__ = 'user'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    roomNumber = db.Column(db.String(20), nullable=False)
    name = db.Column(db.String(50), nullable=False)
    year = db.Column(db.Integer, nullable=False)
    points = db.Column(db.Integer, nullable=False)
    wantUniqueNumber = db.Column(db.Boolean, nullable=False)

    # Foreign key constraints (only can have one)
    flaskUser_id = db.Column(db.Integer,
                             db.ForeignKey('flaskUser.id'),
                             nullable=False)
    gender_id = db.Column(db.Integer,
                          db.ForeignKey('gender.id'),
                          nullable=False)
    preference_id = db.Column(db.Integer, db.ForeignKey('jerseyNumber.id'))
    jerseyNumber_id = db.Column(db.Integer, db.ForeignKey('jerseyNumber.id'))
    # choice_id = db.Column(db.Integer, db.ForeignKey('choice.id'))

    # Relationships
    flaskUser = db.relationship('FlaskUser', backref='users')
    gender = db.relationship('Gender', back_populates="User")
    choice = db.relationship('Choice',
                             back_populates='user',
                             uselist=False,
                             lazy=True)
    sports = db.relationship('Sport', secondary='userSports', lazy=True)
    jerseyNumber = db.relationship('JerseyNumber',
                                   foreign_keys=[jerseyNumber_id],
                                   backref='users',
                                   lazy=True)
    preference = db.relationship('JerseyNumber',
                                 foreign_keys=[preference_id],
                                 backref='users_preference',
                                 lazy=True)
Beispiel #10
0
class JerseyNumber(db.Model):
    __tablename__ = 'jerseyNumber'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    number = db.Column(db.Integer, nullable=False)
    isTaken = db.Column(db.Boolean, default=False, nullable=False)

    gender_id = db.Column(db.Integer,
                          db.ForeignKey('gender.id'),
                          nullable=False)

    #relationship / foreign key constraint
    # one to many relationship (one number can have multiple users)
    # users = db.relationship('User', back_populates="jerseyNumber", lazy=True)
    # user_preference = db.relationship('User', back_populates="preference", lazy=True)
    gender = db.relationship('Gender', back_populates="JerseyNumber")