class UserHasImage(db.Model, CRUD_MixIn): #id = db.Column(db.Integer, primary_key=True) users_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, primary_key=True) images_id = db.Column(db.Integer, db.ForeignKey('images.id'), nullable=False, primary_key=True) progress = db.Column(db.Integer, nullable=True) n_segments = db.Column(db.Integer, nullable=True) crop_orig_filepath = db.Column(db.String(250), nullable=True, unique=True) crop_overlay_filepath = db.Column(db.String(250), nullable=True, unique=True) crop_segm_filepath = db.Column(db.String(250), nullable=True, unique=True) def __init__(self, fullsize_orig_filepath): self.progress = 0
class Users(db.Model, CRUD_MixIn): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(250), nullable=False, unique=True) password = db.Column(db.String(250), nullable=False) name = db.Column(db.String(250), nullable=False) active = db.Column(db.Integer, nullable=False) creation_time = db.Column(db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False) role = db.Column(db.String(250), db.ForeignKey('roles.name')) role_relation = db.relationship('Roles', backref="users") def __init__( self, email, password, name, active, role, ): self.email = email self.password = password self.name = name self.active = active self.role = role
class Comments(db.Model, CRUD_MixIn): id = db.Column(db.Integer, primary_key=True) post_id = db.Column(db.Integer, db.ForeignKey('posts.id'), nullable=False) author_name = db.Column(db.String(250), nullable=False) author_email = db.Column(db.String(250), nullable=False) author_url = db.Column(db.Text) created_on = db.Column( db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False) content = db.Column(db.Text, nullable=False) karma = db.Column(db.Integer, default = 0 ) approved = db.Column(db.String(250), nullable=False) agent = db.Column(db.Text) type = db.Column(db.String(250)) parent = db.Column(db.Integer, default = 0, nullable=False) def __init__(self, post_id, author_name, author_email, author_url, created_on, content, karma, approved, agent, type, parent, ): self.post_id = post_id self.author_name = author_name self.author_email = author_email self.author_url = author_url self.created_on = created_on self.content = content self.karma = karma self.approved = approved self.agent = agent self.type = type self.parent = parent
class Responses(db.Model, CRUD_MixIn): id = db.Column(db.Integer, primary_key=True) question_id = db.Column(db.Integer(), db.ForeignKey('questions.id', ondelete='CASCADE')) user_id = db.Column(db.Integer(), db.ForeignKey('users.id', ondelete='CASCADE')) answer = db.Column(db.String(200)) modification_time = db.Column(db.TIMESTAMP, server_default=db.func.current_timestamp()) def __init__( self, user, answer, question, modification_time, ): self.user = user self.answer = answer self.question = question self.modification_time = modification_time
class Questions(db.Model, CRUD_MixIn): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(250), nullable=False) survey_id = db.Column(db.Integer(), db.ForeignKey('surveys.id', ondelete='CASCADE')) order = db.Column(db.Integer()) creation_time = db.Column(db.TIMESTAMP, server_default=db.func.current_timestamp()) updated = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) # Relationships responses = db.relationship('Responses', backref='questions', lazy='dynamic') def __init__( self, name, ): self.name = name
from marshmallow_jsonapi import Schema, fields from marshmallow import validate from app.basemodels import db, CRUD_MixIn from app.courses.models import Courses student_course=db.Table('student_course', db.Column('studentid', db.Integer,db.ForeignKey('students.id'), nullable=False), db.Column('courseid',db.Integer,db.ForeignKey('courses.id'),nullable=False), db.PrimaryKeyConstraint('studentid', 'courseid') ) class StudentCourse(): def __init__(self,courseid,studentid): self.courseid=courseid self.studentid=studentid db.mapper(StudentCourse, student_course) class Students(db.Model, CRUD_MixIn): id = db.Column(db.Integer, primary_key=True) studentname = db.Column(db.String(250), nullable=False) degree = db.Column(db.String(250), nullable=False) major = db.Column(db.String(250), nullable=False) courses = db.relationship('Courses', secondary=student_course, backref='students') def __init__(self, studentname, degree, major): self.studentname = studentname self.degree = degree
from marshmallow_jsonapi import Schema, fields from marshmallow import validate from app.basemodels import db, CRUD_MixIn from app.terms.models import TermsSchema # Many to Many Relationships with Posts and terms term_relationships=db.Table('term_relationships', db.Column('post_id', db.Integer,db.ForeignKey('posts.id'), nullable=False), db.Column('term_id',db.Integer,db.ForeignKey('terms.id'),nullable=False), db.PrimaryKeyConstraint('post_id', 'term_id') ) class TermRelationships(): def __init__(self,post_id,term_id): self.post_id=post_id self.term_id=term_id db.mapper(TermRelationships, term_relationships) class Posts(db.Model, CRUD_MixIn): id = db.Column(db.Integer, primary_key=True) author = db.Column(db.String(250), nullable=False) title = db.Column(db.Text, nullable=False) slug = db.Column(db.String(250), nullable=False) date = db.Column( db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False) date_gmt = db.Column( db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False) content = db.Column(db.Text, nullable=False)