from project.server import db from project.server.models.base import ModelBase question_category_assignments_table = \ db.Table('question_category_assignments', db.Model.metadata, db.Column('question_id', db.Integer, db.ForeignKey('questions.id')), db.Column('category_id', db.Integer, db.ForeignKey('categories.id')) ) class Category(db.Model, ModelBase): __tablename__ = "categories" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(), nullable=False) @classmethod def include(cls, c): if c in [cls.name]: return True return False
import datetime import jwt from project.server import app, db, bcrypt # Define models users_roles = db.Table( 'user_role', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model): __tablename__ = 'role' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) class User(db.Model): """ User Model for storing user related details """ __tablename__ = "user" id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) admin = db.Column(db.Boolean, nullable=False, default=False) def __init__(self, email, password, admin=False): self.email = email self.password = bcrypt.generate_password_hash( password, app.config.get('BCRYPT_LOG_ROUNDS')).decode()
import typing from sqlalchemy import Index, desc, func, any_, bindparam, asc from project.server import db from project.server.models.crud import CRUDMixin from project.server.models.image import ImageMixin from project.server.models.orderable import OrderableMixin color_device_table = db.Table( 'color_device', db.Column('color_id', db.Integer, db.ForeignKey('color.id')), db.Column('device_id', db.Integer, db.ForeignKey('device.id'))) class Color(db.Model, CRUDMixin): __tablename__ = 'color' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), nullable=False) # public name that is displayed to user's internal_name = db.Column( db.String(128), index=True, unique=True, nullable=False ) # internal name that we use to map colors to manufacturers color_code = db.Column(db.String(20), nullable=False) devices = db.relationship("Device", secondary=color_device_table, back_populates="colors") def __str__(self): return self.name
class Skills(db.Model): """ Skill fo jobs """ __tablename__ = "skills" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), unique=True, nullable=False) level = db.Column(db.Integer, nullable=True) assoc_skills_to_jobb = db.Table( 'skill_job', db.Model.metadata, db.Column('id', db.Integer, primary_key=True), db.Column('skill_id', db.Integer, db.ForeignKey('skills.id')), db.Column('job_id', db.Integer, db.ForeignKey('job_offer.id')), ) class JobOffer(db.Model): """ Job Offer Model """ __tablename__ = "job_offer" id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) title = db.Column(db.String(255), unique=True, nullable=False) description = db.Column(db.String(500), unique=True, nullable=False)
# project/server/models.py import datetime from project.server import db, bcrypt course_student_association_table = db.Table( 'course_student_association', db.metadata, db.Column('student_id', db.Integer, db.ForeignKey('students.id')), db.Column('course_id', db.Integer, db.ForeignKey('courses.id'))) class Course(db.Model): __tablename__ = 'courses' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), unique=True, nullable=False) description = db.Column(db.Text(), nullable=False) subject = db.Column(db.String(255), nullable=False) start_date = db.Column(db.DateTime, nullable=False) end_date = db.Column(db.DateTime, nullable=False) active = db.Column(db.Boolean, nullable=False, default=True) teacher_id = db.Column(db.Integer, db.ForeignKey('teachers.id'), nullable=False) teacher = db.relationship('Teacher', backref='courses') students = db.relationship('Student', secondary=course_student_association_table, backref='courses')
# project/server/models.py import datetime from flask import current_app from project.server import db, bcrypt TrackEvent = db.Table( 'TrackEvent', db.Column('trackId', db.Integer, db.ForeignKey('tracks.id')), db.Column('eventId', db.Integer, db.ForeignKey('events.id'))) RacerSponsor = db.Table( 'RacerSponsor', db.Column('racerId', db.Integer, db.ForeignKey('racers.id')), db.Column('sponsorId', db.Integer, db.ForeignKey('sponsors.id'))) CarRacer = db.Table( 'CarRacer', db.Column('carId', db.Integer, db.ForeignKey('cars.id')), db.Column('racerId', db.Integer, db.ForeignKey('racers.id'))) class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) last_login = db.Column(db.DateTime, nullable=True)
# project/server/models.py import datetime from project.server import app, db, bcrypt #helper table for many-to-many relationship b/w User and Trip users_trips = db.Table( 'users_trips', db.Model.metadata, db.Column('user', db.Integer, db.ForeignKey('users.id'), primary_key=True), db.Column('trip', db.Integer, db.ForeignKey('trips.id'), primary_key=True)) itinerary_events = db.Table( 'itinerary_events', db.Model.metadata, db.Column('itinerary', db.Integer, db.ForeignKey('itineraries.id'), primary_key=True), db.Column('event', db.Integer, db.ForeignKey('events.id'), primary_key=True)) class User(db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False)