class Partner(db.Model): id = db.Column(db.Integer(), primary_key=True, index=True) name = db.Column(db.String(200), index=True, unique=True) opportunities = db.relationship('Opportunity', backref='partner', lazy='dynamic') def __repr__(self): return '<Partner {}>'.format(self.name)
class Opportunity(db.Model): id = db.Column(db.Integer(), primary_key=True, index=True) active = db.Column(db.Boolean()) name = db.Column(db.String(100), index=True, unique=True) job_number = db.Column(db.String(50), unique=True) description = db.Column(db.Text(500)) shift_hours = db.Column(db.Float()) commitment_length = db.Column(db.Float(2)) start_date = db.Column(db.Date()) end_date = db.Column(db.Date()) training_time_required = db.Column(db.Integer()) volunteers_needed = db.Column(db.Integer()) location_street = db.Column(db.String(100)) location_city = db.Column(db.String(50)) location_zip = db.Column(db.String(10)) # One to many relationships partner_id = db.Column(db.Integer, db.ForeignKey('partner.id')) # Many to many relations passions = db.relationship('Passion', secondary='passions', lazy='subquery', backref=db.backref('opportunities', lazy=True)) age_group_interests = db.relationship('AgeGroupInterest', secondary='age_group_interests', lazy='subquery', backref=db.backref('opportunities', lazy=True)) skills = db.relationship('Skill', secondary='skills', lazy='subquery', backref=db.backref('opportunities', lazy=True)) frequencies = db.relationship('Frequency', secondary='frequencies', lazy='subquery', backref=db.backref('opportunities', lazy=True)) def __repr__(self): return '<Opportunity {}>'.format(self.name)
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), index=True, unique=True) password_hash = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) def hash_password(self, password): self.password_hash = pwd_context.hash(password) def verify_password(self, password): return pwd_context.verify(password, self.password_hash) def get_user_roles(self): role_names = [] for r in self.roles: role_names.append(r.name) return role_names
class Role(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))
class Frequency(db.Model): id = db.Column(db.Integer(), primary_key=True, index=True) name = db.Column(db.String(50), index=True, unique=True) def __repr__(self): return '<Frequency {}>'.format(self.name)
class AgeGroupInterest(db.Model): id = db.Column(db.Integer(), primary_key=True, index=True) name = db.Column(db.String(50), index=True, unique=True) def __repr__(self): return '<AgeGroupInterest {}>'.format(self.name)