Ejemplo n.º 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)
Ejemplo n.º 2
0
class Gender(db.Model):
    __tablename__ = 'gender'
    __tableargs__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    genderName = db.Column(db.String(10), nullable=False)

    User = db.relationship('User')
    JerseyNumber = db.relationship('JerseyNumber')
Ejemplo n.º 3
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")
Ejemplo n.º 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')
Ejemplo n.º 5
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")
Ejemplo n.º 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)

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

    user = db.relationship('User', back_populates='choice', lazy=True)
Ejemplo n.º 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)

    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")
Ejemplo n.º 8
0
class FlaskUser(db.Model, UserMixin):
    __tablename__ = 'flaskUser'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)

    email = db.Column(db.String(100), nullable=True)

    def getUser(self):
        return User.query.filter(User.flaskUser_id == self.id).first()

    # User authentication information
    username = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False, server_default='')

    # Relationships
    roles = db.relationship('Role',
                            secondary='flaskUserRoles',
                            backref=db.backref('users', lazy='dynamic'))

    def is_admin(self):
        for role in self.roles:
            if role.name == 'Admin':
                return True
        return False
Ejemplo n.º 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)