class TeamUnit(Base): __table_args__ = (db.PrimaryKeyConstraint('team_id', 'unit_id'), ) team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False) unit_id = db.Column(db.Integer, db.ForeignKey('unit.id'), nullable=False) def __init__(self, team_id, unit_id): self.team_id = team_id self.unit_id = unit_id
class Dispatch(db.Model): __tablename__ = 'dispatch' id_ambulance = db.Column(db.Integer, db.ForeignKey('ambulance.id_ambulance'), nullable=False) id_params_team = db.Column(db.Integer, db.ForeignKey('paramedics_team.id_params_team'), nullable=False) id_emergency = db.Column(db.Integer, db.ForeignKey('emergency.id_emergency'), nullable=False) dispatch_hour = db.Column(db.DateTime, nullable=False) arrival_hour = db.Column(db.DateTime) distance = db.Column(db.Integer) status = db.Column(db.Integer, nullable=False) fee = db.Column(db.Float) __table_args__ = (db.PrimaryKeyConstraint('id_ambulance', 'id_params_team', 'id_emergency'), db.CheckConstraint('status >= 1 AND status <= 5')) def __init__(self, ambulance, paramedics, emergency, dispatch_hour, arrival_hour=None, distance=0, status=1, fee=0): self.id_ambulance = ambulance self.id_params_team = paramedics self.id_emergency = emergency self.dispatch_hour = dispatch_hour self.arrival_hour = arrival_hour self.distance = distance self.status = status self.fee = fee def pretty_status(self): if self.status == 1: return 'En ruta' elif self.status == 2: return 'En el sitio' elif self.status == 3: return 'Volviendo' elif self.status == 4: return 'Completado' elif self.status == 5: return 'Cancelado' else: raise AttributeError( 'status should be some number between 1 and 5')
class RecipeCategory(db.Model): __table_args__ = (db.PrimaryKeyConstraint('recipe_id', 'category_id'), ) recipe_id = db.Column(db.Integer, db.ForeignKey('recipe.id'), nullable=False) category_id = db.Column(db.Integer, db.ForeignKey('category.id'), nullable=False) def __init__(self, recipe_id, category_id): self.recipe_id = recipe_id self.category_id = category_id
class Bookmark(db.Model): date_created = db.Column(db.DateTime, default=db.func.current_timestamp()) date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) name = db.Column(db.String(144), nullable=True) item_id = db.Column(db.Integer, db.ForeignKey("item.id"), nullable=False) account_id = db.Column(db.Integer, db.ForeignKey("account.id"), nullable=False) __table_args__ = ( db.PrimaryKeyConstraint('item_id', 'account_id'), {}, ) def __init__(self, name, item_id, account_id): self.name = name self.item_id = item_id self.account_id = account_id
class Favorite(db.Model): __tablename__ = "Favorite" source_id = db.Column(db.Integer, db.ForeignKey("Profile.id"), nullable=False) target_id = db.Column(db.Integer, db.ForeignKey("Profile.id"), nullable=False) date_created = db.Column(db.DateTime, default=func.now(), server_default=func.now(), nullable=False) __table_args__ = ( db.PrimaryKeyConstraint("source_id", "target_id"), db.CheckConstraint("source_id != target_id"), ) # Can't favorite oneself. def __init__(self, source_id, target_id): self.source_id = source_id self.target_id = target_id
from application import db class Base(db.Model): __abstract__ = True id = db.Column(db.Integer, primary_key=True) date_created = db.Column(db.DateTime, default=db.func.current_timestamp()) date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) kurssimateriaali = db.Table( 'kurssimateriaali', db.Column('course.id', db.Integer, db.ForeignKey('course.id')), db.Column('material.id', db.Integer, db.ForeignKey('material.id')), db.PrimaryKeyConstraint('course.id', 'material.id')) kurssilainen = db.Table( 'kurssilainen', db.Column('account.id', db.Integer, db.ForeignKey('account.id')), db.Column('course.id', db.Integer, db.ForeignKey('course.id')), db.PrimaryKeyConstraint('account.id', 'course.id'))
from application.models import Base from sqlalchemy.sql import text from sqlalchemy.orm import relationship, backref from application.races.models import Race favoritetracks = db.Table( 'favoritetracks', db.Column('player_id', db.Integer, db.ForeignKey('player.id'), primary_key=True), db.Column('track_id', db.Integer, db.ForeignKey('track.id'), primary_key=True), db.PrimaryKeyConstraint('player_id', 'track_id')) class Player(Base): handle = db.Column(db.String(100), nullable=False) account_id = db.Column(db.Integer, db.ForeignKey('account.id'), nullable=False) favoritetracks = db.relationship('Track', secondary=favoritetracks, backref=db.backref('players')) character_id = db.Column(db.Integer, db.ForeignKey('character.id'),
languagescount = db.Column(db.Integer) genrescount = db.Column(db.Integer) #for followers and following followers = db.Table( 'followers', db.Column('follower_id', db.Integer, db.ForeignKey("Users.id")), db.Column('followed_id', db.Integer, db.ForeignKey("Users.id"))) #for preferring language preference = db.Table( 'preference', db.Column('uid', db.Integer, db.ForeignKey("Users.id"), nullable=False), db.Column('lid', db.Integer, db.ForeignKey("Languages.id"), nullable=False), db.PrimaryKeyConstraint('uid', 'lid')) #for subscribing to genres subscription = db.Table( 'subscription', db.Column('uid', db.Integer, db.ForeignKey("Users.id"), nullable=False), db.Column('gid', db.Integer, db.ForeignKey("Genres.id"), nullable=False), db.PrimaryKeyConstraint('uid', 'gid')) #primary language #is_first_login class Users(db.Model): __tablename__ = 'Users' id = db.Column(db.Integer, primary_key=True) User_id = db.Column(db.String(64), index=True, unique=True, nullable=False)
from application import db from application.models import Base from sqlalchemy.sql import text absence_event = db.Table( 'absence_event', db.Column('absence_id', db.Integer, db.ForeignKey('absence.id'), nullable=False), db.Column('event_id', db.Integer, db.ForeignKey('event.id'), nullable=False), db.PrimaryKeyConstraint('absence_id', 'event_id')) class Event(Base): name = db.Column(db.String(144), nullable=False) description = db.Column(db.String(1000)) date_start = db.Column(db.DateTime, nullable=False) date_end = db.Column(db.DateTime, nullable=False) room_id = db.Column(db.Integer, db.ForeignKey('room.id')) absence_events = db.relationship('Absence', secondary=absence_event, backref='event') def __init__(self, name, description, date_start, date_end): self.name = name