コード例 #1
0
ファイル: models.py プロジェクト: alages97/jersey_bidding
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'))
コード例 #2
0
ファイル: models.py プロジェクト: alages97/jersey_bidding
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')
コード例 #3
0
ファイル: models.py プロジェクト: wwongwk/jersey_bidding
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'))
コード例 #4
0
ファイル: models.py プロジェクト: alages97/jersey_bidding
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)
コード例 #5
0
ファイル: models.py プロジェクト: wwongwk/jersey_bidding
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')
コード例 #6
0
ファイル: models.py プロジェクト: alages97/jersey_bidding
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")
コード例 #7
0
ファイル: models.py プロジェクト: wwongwk/jersey_bidding
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")
コード例 #8
0
ファイル: models.py プロジェクト: alages97/jersey_bidding
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")
コード例 #9
0
ファイル: models.py プロジェクト: alages97/jersey_bidding
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'))
コード例 #10
0
ファイル: models.py プロジェクト: wwongwk/jersey_bidding
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)
コード例 #11
0
ファイル: models.py プロジェクト: wwongwk/jersey_bidding
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)
コード例 #12
0
ファイル: models.py プロジェクト: wwongwk/jersey_bidding
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
コード例 #13
0
ファイル: models.py プロジェクト: wwongwk/jersey_bidding
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)