class Patient(UserMixin, CommonUser ): # Creates the schema for a 'User table' within our database. __tablename__ = 'patient' # Sets SQL database table name. username = db.Column(db.String(50), primary_key=True, unique=True, nullable=False) medical_conditions = db.Column(db.String(500)) requires_urgent_help = db.Column( db.Boolean, nullable=False) # If set to True, we get urgent help for our patient. # Relationships ------------------------------------------------------------------------ psychiatrist_id = db.Column(db.String(16), db.ForeignKey('psychiatrist.bacp_number')) psychiatrist = db.relationship('Psychiatrist', back_populates='patients') feelings = db.relationship('PatientFeelings', back_populates='patient') # Class Method Override --------------------------------------------------------------- def get_id(self): # Returns the username as our user's primary 'id'. return self.username
class HubPost(db.Model): __tablename__ = 'hub_post' post_hash_key = db.Column(db.String(64), primary_key=True) created = db.Column(db.DateTime, nullable=False, index=True, default=datetime.datetime.utcnow()) post_id = db.Column(db.String, nullable=False, index=True, unique=True) author = db.relationship(HubUser, secondary='link_author', backref='hub_post', uselist=False) post_content = db.relationship( 'SatPostContent', backref='hub_post', uselist=False, primaryjoin="and_(HubPost.post_hash_key==SatPostContent.post_hash_key, " f"SatPostContent.record_end > '{datetime.datetime.utcnow()}')") effectivity = db.relationship( 'SatPostEffectivity', backref='hub_post', uselist=False, primaryjoin= "and_(HubPost.post_hash_key==SatPostEffectivity.post_hash_key, " f"SatPostEffectivity.record_end > '{datetime.datetime.utcnow()}')") __mapper_args__ = {"order_by": created.desc()}
class Admin(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(100), nullable=False) pwd = db.Column(db.String(200), nullable=False) is_super = db.Column(db.SmallInteger, nullable=False) Adminlogs = db.relationship("Adminlog", backref='Admin', lazy="dynamic") Oplogs = db.relationship("Oplog", backref='Admin', lazy="dynamic")
class User(UserMixin, db.Model): __tablename__ = "portfolio_user" id = db.Column(db.Integer, primary_key=True) """User's id""" email = db.Column(db.String(128), index=True, unique=True, nullable=False) """User's email""" password_hash = db.Column(db.String(128), nullable=False) """User's hashed password""" accounts = db.relationship('InvestmentAccount') """Accounts owned by the user""" stock_transactions = db.relationship('StockTransaction') """StockTransactions beloning to the user""" def __iter__(self): yield ('email', self.email) def __repr__(self): return '<User {}>'.format(self.id) def set_password(self, password): """ Hashes the password and saves it as the user's password_hash Keyword arguments: password -- the user's password """ self.password_hash = generate_password_hash(password) def check_password(self, password): """ Hashes the password and checks if it is equal to the user's password_hash Keyword arguments: password -- the user's password """ return check_password_hash(self.password_hash, password)
class comment(db.Model): id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) movie_id = db.Column(db.INTEGER, db.ForeignKey('movie.id', onupdate="SET NULL", ondelete="SET NULL"), nullable=True) movieId = db.relationship("movie", back_populates='comments') user_id = db.Column(db.INTEGER, db.ForeignKey('user.id', onupdate="SET NULL", ondelete="SET NULL"), nullable=True) userId = db.relationship("user", back_populates="comments")
class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) user = db.relationship('User', backref=db.backref('posts', lazy=True)) title = db.Column(db.String(255)) slug = db.Column(db.String(255)) text = db.Column(db.Text) html = db.Column(db.Text) tags = db.relationship('Tag', secondary=posts_tags_association, lazy='subquery', backref=db.backref('posts', lazy=True)) isPrivate = db.Column(db.Boolean, default=False) createdAt = db.Column(db.DateTime, default=datetime.utcnow) # auto_now_add=True updatedAt = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) @validates('title') def update_slug(self, key, value): self.slug = slugify(value) return value @validates('text') def update_html(self, key, value): self.html = markdown.markdown(value) return value
class admin(db.Model): id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) name = db.Column(db.String(30), nullable=False) pwd = db.Column(db.String(30), nullable=False) is_super = db.Column(db.SmallInteger, nullable=False) oplogs = db.relationship("oplog", back_populates="adminId") adminlogs = db.relationship("adminlog", back_populates="adminId")
class Sex(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) type = db.Column(db.String(25), unique=True, nullable=False) user = db.relationship('Users', backref='sex', lazy=True) admin = db.relationship('Admin', backref='sex', lazy=True) def __repr__(self): return '<Sex %r>' % self.type
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) blog_id = db.Column(db.ForeignKey(Blog.id), nullable=False) user_id = db.Column(db.ForeignKey(User.id), nullable=False) content = db.Column(db.String, nullable=False) created_at = db.Column(db.DateTime, nullable=False, server_default=db.func.current_timestamp()) authoruser = db.relationship(User, lazy="joined", backref="comments") authorblog = db.relationship(Blog, lazy="joined", backref="comments")
class Startup(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False, default="") email = db.Column(db.String(50), nullable=False, default="") startup_date = db.Column(db.Date) description = db.Column(db.String(300)) password_hash = db.Column(db.String(128)) location = db.Column(db.String(100)) markerText = db.Column(db.String(100)) tags = db.relationship('Tag', secondary='tag_map', backref=db.backref('startup', lazy='dynamic')) job_positions = db.relationship('Job_position', backref='publishded_by', lazy=True) profile_picture = db.Column(db.String(30), default="profile_man.jpg") def generate_data(): import datetime db.session.add( dummydataStartUp("Mesla", "melon_dusk", "Vi lager biler som kjører på møkk", "San Fransisco", 1, "Mesla.png")) db.session.add( dummydataStartUp("Den Kebabnorske Bank", "bankfloss", "Whallah, vi låner deg floos brur", "Oslo", 3, "KebabnorskBank.png")) db.session.add( dummydataStartUp("MoTube", "motube", "Forum for kuvideoer", "San Fransisco", 1, "MoTube.png")) db.session.add( dummydataStartUp("KanAkademi", "notkhan", "Free education 4 stupid people", "San Fransisco", 15, "KanAkademi.png")) db.session.add( dummydataStartUp( "AiDiabitus", "diabetus", "Vi lager en AI som sier at du er feit og holder på å få diabetes", "San Fransisco", 6, "AiDiabitus.png")) db.session.add( dummydataStartUp( "IkkeA", "billigmobler", "Billig møbler om har alt for vanskelige instrukser", "stockholm", 8, "IkkeA.png")) try: db.session.commit() print("ADDED STARTUPS") except: db.session.rollback() def _repr_(self): return '<user{}>'.format(self.email) def __str__(self): return "Startup: {}".format(self.email)
class admin(db.Model): id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) name = db.Column(db.String(30), nullable=False, unique=True) pwd = db.Column(db.String(32), nullable=False) is_super = db.Column(db.SmallInteger, nullable=False) addTime = db.Column(db.DateTime, index=True, nullable=False, default=datetime.datetime.now()) oplogs = db.relationship("oplog", back_populates="adminId") adminlogs = db.relationship("adminlog", back_populates="adminId") roles = db.relationship('role', back_populates='admin')
class Artist(db.Model): __tablename__ = 'artists' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) created_at = db.Column(db.DateTime, nullable=False) updated_at = db.Column(db.DateTime, nullable=False) songs = db.relationship('Song', backref='artist', lazy=True) albums = db.relationship('Album', backref='artist', lazy=True)
class role(db.Model): id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) name = db.Column(db.String(30), nullable=False, unique=True) auths = db.relationship("auth", back_populates="role") addTime = db.Column(db.DateTime, index=True, nullable=False, default=datetime.datetime.now()) admin_id = db.Column('admin', db.ForeignKey('admin.id', ondelete="SET NULL")) admin = db.relationship('admin', back_populates='roles') def __repr__(self): return "%s" % (self.name)
class Persona(UserMixin, db.Model): __tablename__ = 'persona' __table_args__ = (db.CheckConstraint( "(cf)::text ~ '^[A-Z]{6}\\d{2}[A-Z]\\d{2}[A-Z]\\d{3}[A-Z]$'::text"), ) id_persona = db.Column( db.Integer, primary_key=True, server_default=db.text("nextval('persona_id_persona_seq'::regclass)")) nome = db.Column(db.String(50), nullable=False) cognome = db.Column(db.String(50), nullable=False) username = db.Column(db.String(50), nullable=False) password = db.Column(db.String(50), nullable=False) cf = db.Column(db.String(16), nullable=False, unique=True) id_indirizzo = db.Column(db.Integer, db.ForeignKey('indirizzo.id_indirizzo'), nullable=False, unique=True) id_email = db.Column(db.Integer, db.ForeignKey('email.id_email'), nullable=False, unique=True) id_documento = db.Column(db.Integer, db.ForeignKey('documento.id_documento'), nullable=False, unique=True) id_telefono = db.Column(db.Integer, db.ForeignKey('telefono.id_telefono'), nullable=False, unique=True) luogo_nascita = db.Column(db.String(50), nullable=False) data_nascita = db.Column(db.Date, nullable=False) indirizzo = db.relationship('Indirizzo', foreign_keys=[id_indirizzo], uselist=False) email = db.relationship('Email', foreign_keys=[id_email]) documento = db.relationship('Documento', foreign_keys=[id_documento]) telefono = db.relationship('Telefono', foreign_keys=[id_telefono]) def get_id(self): return self.id_persona def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) @login_manager.user_loader def load_user(id_persona): return Persona.query.get(int(id_persona))
class Group(BaseModel): """ 组模型 """ __tablename__ = "group" name = Column("name", db.String(32), nullable=False, comment="角色名称") leaderId = Column("leader_id", db.String(64), db.ForeignKey('user.id'), nullable=False, comment="队长ID") leader = db.relationship("User") menbers = db.relationship('User', secondary="user_group", backref="groups")
class Publisher(SearchableMixin, FlagMixin, db.Model): __sayt__ = 'name' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), index=True) series = db.relationship('Serie', backref='publisher', lazy='dynamic') books = db.relationship('Book', backref='publisher', lazy='dynamic') def __str__(self): return self.name @property def is_incorrect(self): return self.incorrect or any((x.incorrect for x in self.series))
class Ricetta(db.Model): __tablename__ = 'ricetta' id_ricetta = db.Column( db.Integer, primary_key=True, server_default=db.text("nextval('ricetta_id_ricetta_seq'::regclass)")) id_paziente = db.Column(db.Integer, db.ForeignKey('paziente.id_paziente')) id_medico = db.Column(db.Integer, db.ForeignKey('medico.id_medico')) campo = db.Column(db.String(300), nullable=False) data_emissione = db.Column(db.Date, nullable=False) medico = db.relationship('Medico') paziente = db.relationship('Paziente')
class User(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.String(80), nullable=False) items = db.relationship('Item', backref=db.backref('user', lazy=True)) categories = db.relationship('Category', backref=db.backref('user', lazy=True)) auditLogs = db.relationship('AuditLog', backref=db.backref('user', lazy=True)) created_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) def __init__(self, user_id): self.user_id = user_id
class Like(db.Model): __tablename__ = 'Like' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('User.id'), nullable=False) user = db.relationship('User', foreign_keys=[user_id]) tweet_id = db.Column(db.Integer, db.ForeignKey('Tweet.id'), nullable=False) tweet = db.relationship('Tweet', foreign_keys=[tweet_id]) def serialize(self): return { 'id': self.id, 'user_id': self.user_id, 'tweet_id': self.tweet_id }
class user(db.Model): id = db.Column(db.INTEGER,primary_key=True,autoincrement=True) username = db.Column(db.String(300),nullable=False) pwd = db.Column(db.String(300),nullable=False) name = db.Column(db.String(400),nullable=True) email = db.Column(db.String(300),nullable=False) phone = db.Column(db.String(300),nullable=False) info = db.Column(db.Text,nullable=True) face = db.Column(db.String(300),nullable=True) usertime = db.Column(db.DateTime,nullable=True,default=datetime.datetime.now()) uuid = db.Column(db.String(300),nullable=True,default=gen_id) userid = db.relationship("login_log", backref='user', lazy="dynamic") comments = db.relationship("comment", backref='user', lazy="dynamic") collections = db.relationship("collection", backref='user', lazy="dynamic")
class user(db.Model): id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) userName = db.Column(db.String(30), nullable=False) pwd = db.Column(db.String(32), nullable=False) nickname = db.Column(db.String(50), nullable=True) email = db.Column(db.String(30), nullable=False) phone = db.Column(db.String(30), nullable=False) info = db.Column(db.Text, nullable=True) face = db.Column(db.String(30), nullable=True) loginTime = db.Column(db.String(30), nullable=True, default=datetime.datetime.now()) uuid = db.Column(db.String(32), nullable=True, default=gen_id) loginlogs = db.relationship("loginlog", back_populates='userId') comments = db.relationship("comment", back_populates='userId') collections = db.relationship("collection", back_populates='userId')
class Medico(db.Model): __tablename__ = 'medico' id_medico = db.Column(db.Integer, db.ForeignKey('persona.id_persona'), primary_key=True) id_studio = db.Column(db.Integer, db.ForeignKey('stud_leg.id_studio'), unique=True) persona = db.relationship('Persona', foreign_keys=[id_medico]) stud_leg = db.relationship('StudLeg', foreign_keys=[id_studio]) def __init__(self, id_medico, id_studio): self.id_medico = id_medico self.id_studio = id_studio
class HashtagType(db.Model): __tablename__ = 'HashtagType' id = db.Column(db.Integer, primary_key=True, nullable=False) hashtag_id = db.Column(db.Integer, db.ForeignKey('Hashtag.id'), nullable=False) hashtag = db.relationship('Hashtag', foreign_keys=[hashtag_id]) tweet_id = db.Column(db.Integer, db.ForeignKey('Tweet.id'), nullable=False) tweet = db.relationship('Tweet', foreign_keys=[tweet_id]) def serialize(self): return { 'id': self.id, 'hashtag_id': self.hashtag_id, 'tweet_id': self.tweet_id }
class tag(db.Model): id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) tagName = db.Column(db.String(50), nullable=False) addTime = db.Column(db.Date, index=True, nullable=False, default=datetime.datetime.now()) movies = db.relationship("movie", secondary=movie_tag, back_populates="tags")
class oplog(db.Model): id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) admin_id = db.Column(db.INTEGER, db.ForeignKey('admin.id', onupdate="SET NULL", ondelete="SET NULL"), nullable=True) ip = db.Column(db.String(100), nullable=False) operate = db.Column(db.Text, nullable=False) addTime = db.Column(db.DateTime, index=True, nullable=False, default=datetime.datetime.now()) adminId = db.relationship("admin", back_populates="oplogs")
class Post(db.Model): """Feed post model.""" __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True) source_id = db.Column( db.Integer, db.ForeignKey("source.id"), nullable=False, ) title = db.Column(db.String(64), nullable=False) content = db.Column(db.Text()) link = db.Column(db.String(2000), nullable=False, unique=True) author = db.Column(db.String(64), nullable=False) fetched_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) published_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) source = db.relationship("Source", backref="posts") def __repr__(self): return '<Post {}>'.format(self.title)
class Person(SearchableMixin, FlagMixin, db.Model): __sayt__ = 'name' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128)) born = db.Column(db.String(64), nullable=True) # wylatuje creator = db.relationship('Creator', backref='person', lazy='dynamic') def __str__(self): if self.born: return f'{self.name}, ur. {self.born}' return self.name @property def is_incorrect(self): return self.incorrect def author(self): return Creator.query.filter_by(role='A', person=self) def translator(self): return Creator.query.filter_by(role='T', person=self) def redaction(self): return Creator.query.filter_by(role='R', person=self) def introduction(self): return Creator.query.filter_by(role='I', person=self)
class AbsenceLog(db.Model): __tablename__ = 'absencelogs' __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'), db.ForeignKeyConstraint(['person_id', 'yymm', 'dd'], [ 'performlogs.person_id', 'performlogs.yymm', 'performlogs.dd' ], onupdate='CASCADE', ondelete='CASCADE'), db.ForeignKeyConstraint(['person_id'], ['persons.id']), db.ForeignKeyConstraint(['staff_id'], ['persons.id']), db.Index('absencelogs_yymmdd', 'yymm', 'dd'), { 'mysql_engine': 'InnoDB' }) person_id = db.Column(db.String(36)) # 利用者ID yymm = db.Column(db.String(8)) # 年月 dd = db.Column(db.Integer) # 日 enabled = db.Column(db.Boolean) # 月に4回以上であればFalse deleted = db.Column(db.Boolean) # 欠席加算のチェックオフになったらTrue contact = db.Column(db.Date) # 連絡日 staff_id = db.Column(db.String(36)) # 対応職員 reason = db.Column(db.String(128)) # 欠席理由 remarks = db.Column(db.String(128)) # 相談援助 create_at = db.Column(db.DateTime, default=_get_now) update_at = db.Column(db.DateTime, onupdate=_get_now) performlog = db.relationship('PerformLog', back_populates="absencelog") def populate_form(self, form): form.populate_obj(self) @classmethod def get(cls, id, yymm, dd): return cls.query.filter(cls.person_id == id, cls.yymm == yymm, cls.dd == dd).first()
class List(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) items = db.relationship('Item', backref='list', lazy=True) def __repr__(self): return f"<List('{self.id}', '{self.name}', '{self.items}]')>"
class Paziente(db.Model): __tablename__ = 'paziente' id_paziente = db.Column(db.Integer, db.ForeignKey('persona.id_persona'), primary_key=True) id_medico = db.Column(db.Integer, db.ForeignKey('medico.id_medico'), nullable=False) persona = db.relationship('Persona', foreign_keys=[id_paziente]) medico = db.relationship('Medico', foreign_keys=[id_medico]) def __init__(self, id_paziente, id_medico): self.id_paziente = id_paziente self.id_medico = id_medico