Exemplo n.º 1
0
class SurveyAnswers(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    choice_id = db.Column(db.Integer,
                          db.ForeignKey('survey_options.id'),
                          nullable=False)
    student = db.Column(db.Integer,
                        db.ForeignKey('athlete.id'),
                        nullable=False)
Exemplo n.º 2
0
class Athlete(User):
    __tablename__ = 'athlete'
    _simple_fields = User._info_fields + ['team_id']
    _complex_fields = ['surveys']

    id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    team_id = db.Column(db.Integer, db.ForeignKey('team.id'))
    surveys = db.relationship("Survey",
                              secondary=survey_assignment_table,
                              back_populates='assignees')

    def info(self, fields=None):
        i = self._info_complex(fields=fields)
        i.update({"type": "athlete"})
        return i
Exemplo n.º 3
0
class SurveyOptions(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    survey_id = db.Column(db.Integer,
                          db.ForeignKey('survey.id'),
                          nullable=False)
    option = db.Column(db.Text, nullable=False)
    score = db.Column(db.Integer, nullable=False)
    # lazy='joined' makes sure that when an option is queried, all its
    # matching answers come back on the same query
    answers = db.relationship('SurveyAnswers', backref='choice', lazy='joined')
Exemplo n.º 4
0
class Coach(User):
    # have to specify, as we need a reference to this table for the M2M relationship between coaches and teams.
    __tablename__ = 'coach'
    _simple_fields = User._info_fields
    _complex_fields = ['teams']

    id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    teams = db.relationship("Team",
                            secondary=team_association_table,
                            back_populates='coaches')

    def info(self, fields=None):
        i = self._info_complex(fields=fields)
        i.update({"type": "coach"})
        return i
Exemplo n.º 5
0
    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return '<User {}>'.format(self.email)


@login.user_loader
def load_user(id):
    return User.query.get(int(id))


# explicit M2M relationship bridge table
team_association_table = db.Table(
    'team_association_table',
    db.Column('coach_id', db.Integer, db.ForeignKey('coach.id')),
    db.Column('team_id', db.Integer, db.ForeignKey('team.id')),
)

# bridges for days
survey_assignment_table = db.Table(
    'survey_assignment_table',
    db.Column('athlete_id', db.Integer, db.ForeignKey('athlete.id')),
    db.Column('survey_id', db.Integer, db.ForeignKey('survey.id')),
    db.Column('taken', db.Boolean, nullable=False, default=False))


class Coach(User):
    # have to specify, as we need a reference to this table for the M2M relationship between coaches and teams.
    __tablename__ = 'coach'
    _simple_fields = User._info_fields