class Store(db.Model, TimeStampMixin, SerializableModelMixin): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) category = db.Column(db.Enum('korean', 'western', 'soup', 'pork', 'beef', 'chinese', 'noodle'), nullable=False)
class Todo(db.Model): id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String(255), nullable = False) status = db.Column(db.String(30), nullable = False )
class Account(db.Model): id = db.Column(db.Integer, primary_key=True) date_created = db.Column(db.DateTime(timezone=True), default=db.func.current_timestamp()) date_modified = db.Column(db.DateTime(timezone=True), default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) firstname = db.Column(db.String(256), nullable=False) lastname = db.Column(db.String(256), nullable=False) email = db.Column(db.String(256), nullable=False, unique=True) password = db.Column(db.String(256), nullable=False) polls = db.relationship("Poll", backref="owner", lazy=True) roles = db.relationship("Account_role", backref="account", lazy=True) @staticmethod def order66(neo_is_the_one): stmt = text("DELETE FROM account WHERE id !=:neo").params( neo=int(neo_is_the_one)) res = db.engine.execute(stmt) @staticmethod def get_random_id(): stmt = text("SELECT id FROM account ORDER BY RANDOM() LIMIT 1") res = db.engine.execute(stmt) return res.first() def __init__(self, firstname, lastname, email, password, skip_password=False): self.firstname = firstname self.lastname = lastname self.email = email if skip_password == False: self._set_password(password) else: self.password = "******" def _set_password(self, plaintext): self.password = bcrypt.generate_password_hash(plaintext).decode( 'utf-8') def is_correct_password(self, plaintext): return bcrypt.check_password_hash(self.password, plaintext) def is_active(self): return True def is_anonymous(self): return False def is_authenticated(self): return True def get_id(self): return self.id def has_role(self, role): role = role.upper() for r in self.roles: if role == r.name: return True return False
class Image(db.Model): __tablename__ = 'images' id = db.Column(db.Integer, primary_key=True) file_key = db.Column(db.String(60), nullable=False, server_default=db.FetchedValue(), info='文件名') created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='插入时间')
class Base(db.Model): __abstract__ = True id = db.Column(db.Integer, primary_key=True)
class MemberAddres(db.Model): __tablename__ = 'member_address' __table_args__ = ( db.Index('idx_member_id_status', 'member_id', 'status'), ) id = db.Column(db.Integer, primary_key=True) member_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) nickname = db.Column(db.String(20), nullable=False, server_default=db.FetchedValue()) mobile = db.Column(db.String(11), nullable=False, server_default=db.FetchedValue()) province_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) province_str = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue()) city_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) city_str = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue()) area_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) area_str = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue()) address = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue()) status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) is_default = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue()) updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue()) created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
class Characters(db.Model): name = db.Column(db.String(100), nullable=False, primary_key=True) species = db.Column(db.String(100), nullable=False) description = db.Column(db.String(1000), nullable=False) weapon = db.Column(db.String(100), nullable=False) ab1 = db.Column(db.String(100), nullable=False) ab1_des = db.Column(db.String(10000), nullable=False) ab1_enemy = db.Column(db.String(100), nullable=False) ab2 = db.Column(db.String(100), nullable=False) ab2_des = db.Column(db.String(1000), nullable=False) ab2_enemy = db.Column(db.String(100), nullable=False) sab = db.Column(db.String(100), nullable=False) sab_des = db.Column(db.String(1000), nullable=False) sab_enemy = db.Column(db.String(100), nullable=False) def __repr__(self): return ''.join([ 'Name: ', self.name, '\r\n', 'Species: ', self.species, '\r\n', 'History: ', self.description, '\r\n', 'weapon: ', self.weapon, '\r\n', 'primary ability: ', self.ab1, '\r\n', 'Description: ', self.ab1_des, '\r\n' 'Secondary Ability: ', self.ab2, '\r\n', 'Description: ', self.ab2_des, '\r\n', 'Ultimate Ability: ', self.sab, '\r\n', 'Description: ', self.sab_des ])
class Patient_Tests(db.Model): __tablename__ = "patient_tests" #Contains Patient ID against the IDs of the tests assinged to them. id = db.Column(db.Integer, primary_key=True) test_id = db.Column(db.Integer) patient_id = db.Column(db.Integer)
class login_details(db.Model): __tablename__ = 'login_details' #Contains the email and hashed password of the 3 users. id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) accesslevel = db.Column(db.Integer)
class Tests(db.Model): __tablename__ = "tests" # Contains all the test available in the hospital. test_id = db.Column(db.Integer, primary_key=True) test_name = db.Column(db.String(255)) test_charge = db.Column(db.Integer)
class Patient_Medicine(db.Model): __tablename__ = "patient_medicine" # Contains Patient ID against the IDs of the medicines issued to them. id = db.Column(db.Integer, primary_key=True) patient_id = db.Column(db.Integer) medicine_id = db.Column(db.Integer) quantity_issued = db.Column(db.Integer)
class Medicine(db.Model): __tablename__ = "medicines" # contains all the available medicines in the hospital and their available quantities. medicine_id = db.Column(db.Integer, primary_key=True) medicine_name = db.Column(db.String(255)) medicine_rate = db.Column(db.Integer) medicine_quantity = db.Column(db.Integer)
from flask_security import Security, SQLAlchemyUserDatastore, RoleMixin, login_required, current_user from flask_security.utils import encrypt_password from flask_admin.contrib.sqla import ModelView from flask_admin.contrib import sqla from flask_admin import helpers as admin_helpers from flask_login import UserMixin @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) # Define models roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __str__(self): return self.name class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255))
class Series(Base): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(144), nullable=False) episodes_total = db.Column(db.Integer, nullable=False) account_id = db.Column(db.Integer, db.ForeignKey('account.id'), nullable=False) def __init__(self, name): self.name = name self.episodes_total = 0 @staticmethod def find_series(): stmt = text("SELECT id, name, episodes_total " "FROM series " "ORDER BY series.name ASC") res = db.engine.execute(stmt) response = [] for row in res: response.append({ "id": row[0], "name": row[1], "episodes_total": row[2] }) return response @staticmethod def find_series_with_no_episodes(): stmt = text("SELECT name FROM Series WHERE episodes_total = 0") res = db.engine.execute(stmt) response = [] for row in res: response.append({"name": row[0]}) return response @staticmethod def find_most_popular_series(): stmt = text( "SELECT series.name AS name, COUNT(user_series.series_id) AS amount " "FROM user_series INNER JOIN series ON user_series.series_id = series.id " "GROUP BY series.name " "ORDER BY amount DESC LIMIT 5") res = db.engine.execute(stmt) response = [] for row in res: response.append({"name": row[0], "amount": row[1]}) return response @staticmethod def find_recently_watched_series(): if os.environ.get("HEROKU"): stmt = text( "SELECT DISTINCT ON (series.id) series.id, series.name AS name, user_series.date_modified " "FROM user_series INNER JOIN series ON user_series.series_id = series.id " "WHERE user_series.date_modified >= now() - interval '24 hour' " "LIMIT 10") else: stmt = text( "SELECT DISTINCT series.id, series.name AS name " "FROM user_series INNER JOIN series ON user_series.series_id = series.id " "WHERE user_series.date_modified >= datetime('now','-1 day') " "ORDER BY user_series.date_modified DESC LIMIT 10") res = db.engine.execute(stmt) response = [] for row in res: response.append({"name": row[1]}) return response