Esempio 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)
Esempio 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')
Esempio n. 3
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')
Esempio n. 4
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")
Esempio n. 5
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)
Esempio n. 6
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
Esempio n. 7
0
class Role(db.Model):
    __tablename__ = 'role'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(50), unique=True)