class Running(db.Model): __tablename__ = 'running' id = db.Column(db.Integer, primary_key=True) account_id = db.Column(db.Integer, db.ForeignKey('account.id'), unique=True, nullable=False) start = db.Column(db.DateTime(), nullable=False) end = db.Column(db.DateTime(), nullable=False) def __repr__(self): return '<Running %r %r:%r>' % (self.account_id, str( self.start), str(self.end))
class TimeTable(db.Model): __tablename__ = 'timetable' id = db.Column(db.Integer, primary_key=True) account_id = db.Column(db.Integer, db.ForeignKey('account.id'), nullable=False) start = db.Column(db.DateTime(), nullable=False) end = db.Column(db.DateTime(), nullable=False) def to_json(self): return {"start": str(self.start), "end": str(self.end)} def __repr__(self): return '<TimeTable %r %r:%r>' % (self.account_id, str( self.start), str(self.end))
class Events(db.Model): __tablename__ = 'data_events' id = db.Column(db.Integer, primary_key=True) date = db.Column(db.Date, nullable=False) time = db.Column(db.Time) title = db.Column(db.Text(255), nullable=False) event_content = db.Column(db.Text(), nullable=False) created_on = db.Column(db.DateTime(), default=datetime.utcnow) updated_on = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) user_email = db.Column(db.Integer(), db.ForeignKey('users.email')) def __init__(self, date, time, title, event_content): self.date = date self.time = time self.title = title self.event_content = event_content
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(50), nullable=False, unique=True) email = db.Column(db.String(100), nullable=False, unique=True) password_hash = db.Column(db.String(100), nullable=False) created_on = db.Column(db.DateTime(), default=datetime.utcnow) updated_on = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) events = db.relationship('Events', backref='author') def __repr__(self): return "<{}:{}>".format(self.id, self.username) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password)
class NewsletterSubscription(db.Model): """ TODO: We use reccommended SQLite's native functions for generating slugs. There is extremely unlikely chance for collision. Create DB based collision avoidant function for handling this. And yes, it is possible to make, no excuses. """ id = db.Column(db.Integer, primary_key=True) slug = db.Column(db.String, unique=True, nullable=False, default=select( [func.lower(func.hex(func.randomblob(16)))])) email = db.Column(db.String, unique=True, nullable=False) confirmed = db.Column(db.Boolean, default=False) modified_at = db.Column(db.DateTime(timezone=True), default=func.now()) created_at = db.Column(db.DateTime(timezone=True), server_default=func.now()) def __repr__(self): return '<NewsletterSubscription id: {} email: {} confirmed: {}>'.format( self.id, self.email, self.confirmed)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean(), default=False) confirmed_at = db.Column(db.DateTime()) accounts = db.relationship('Account', backref='user', lazy=True) parent_id = db.Column(db.Integer, db.ForeignKey('user.id')) affiliates = db.relationship("User") def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) def __repr__(self): return '<User %r>' % self.email
class Appointment(db.Model): """docstring for Appointment""" __tablename__ = "Appointment" id_appointment = db.Column(db.Integer, nullable=False, primary_key=True) date = db.Column(db.DateTime(), nullable=False) description = db.Column(db.Text(length=None), nullable=False, ) weight = db.Column(db.Float(), nullable=True) height = db.Column(db.Float(), nullable=True) temperature = db.Column(db.Float(), nullable=True) heart_rate = db.Column(db.Float(), nullable=True) done = db.Column(db.Boolean(), nullable=False) username = db.Column(db.String(30),db.ForeignKey( 'User.username'),nullable=False ) id_patient = db.Column(db.String(10),db.ForeignKey( 'Patient.id_patient'),nullable=False ) def __repr__(self): return '{},{},{},{},{},{},{}, {}, {}, {}|'.format(self.id_appointment, self.date, self.description, self.weight, self.height, self.temperature, self.heart_rate, self.done, self.username, self.id_patient)