class Data(db.Model): __tablename__ = 'data' id = db.Column(db.Integer, primary_key=True) value1 = db.Column(db.String()) value2 = db.Column(db.Float) value3 = db.Column(db.Boolean) creationDate = db.Column(db.Integer, nullable=False) timeStamp = db.Column(db.Integer, nullable=False) lastModificationDate = db.Column(db.Integer, nullable=False) def __init__(self, value1, value2, value3, timestamp): self.value1 = value1 self.value2 = value2 self.value3 = value3 self.timeStamp = timestamp self.creationDate = int(time.time()) self.lastModificationDate = int(time.time()) def serialize(self): return { '_id': self.id, 'timestamp': self.timeStamp, 'value1': self.value1, 'value2': self.value2, 'value3': self.value3, 'creationDate': self.creationDate, 'lastModificationDate': self.lastModificationDate }
class Stats(db.Model): __tablename__ = 'stats' id = db.Column(db.Integer, primary_key=True) team_id = db.Column(db.Integer) season = db.Column(db.String(128)) off_rtg = db.Column(db.Float) def_rtg = db.Column(db.Float) pace = db.Column(db.Float) pt_diff = db.Column(db.Float) def __init__(self, team_id, season, off_rtg, def_rtg, pace, pt_diff): """ Create an instance of the Stats model. """ self.team_id = team_id self.season = season self.off_rtg = off_rtg self.def_rtg = def_rtg self.pace = pace self.pt_diff = pt_diff @classmethod def add(cls, stats): """ Persist an instance of the Stats model. """ db.session.add(stats) db.session.commit()
class User(db.Model): __table_name__ = "user" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), nullable=False, unique=True) email = db.Column(db.String(200), nullable=False, unique=True) password = db.Column(db.String(200)) is_active = db.Column(db.Boolean(), default=False) created_at = db.Column(db.DateTime(), nullable=False, server_default=db.func.now()) updated_at = db.Column( db.DateTime(), nullable=False, server_default=db.func.now(), onupdate=db.func.now(), ) events = db.relationship("Event", backref="user") @classmethod def get_by_username(cls, username): return cls.query.filter_by(username=username).first() @classmethod def get_by_email(cls, email): return cls.query.filter_by(email=email).first() def save(self): db.session.add(self) db.session.commit()
class About(db.Model): __tablename__ = "about" id = db.Column(db.Integer, primary_key=True) intro = db.Column(db.String(3000)) image = db.Column(db.String(250)) general_id = db.Column(db.Integer, db.ForeignKey("general.id")) general = relationship("General", back_populates="about") def __repr__(self): return "<About(intro='%s', image='%s')>" % (self.intro, self.image) @property def serialized(self): return { "intro": self.intro, "image": self.image, }
class Setting(db.Model): __tablename__ = 'setting' id = db.Column(db.Integer, primary_key=True) key = db.Column(db.String(128), nullable=False) value = db.Column(db.String(128), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) @classmethod def get_by_user(cls, user_id): return cls.query.filter_by(user_id=user_id) @classmethod def save(cls, settings): for setting in settings: db.session.add(setting) db.session.commit()
class Country(db.Model): id = Column(db.Integer, primary_key=True) country_name = db.Column(String(150), nullable=False, unique=True) def __init__(self, country_name): self.country_name = country_name def __repr__(self): return '<Country %r>' % self.country_name
class SavedRecipe(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) user = db.relationship('User', backref=db.backref('savedrecipes', lazy=True)) recipe_id = db.Column(db.Integer, db.ForeignKey('recipe.id', ondelete="CASCADE"), nullable=False) recipe = db.relationship('Recipe', backref=db.backref('savedrecipes', lazy=True)) UniqueConstraint('user_id', 'recipe_id', name='savedrecipe_user_recipe_uc') def __init__(self, user, recipe): self.user = user self.recipe = recipe
class User(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(80), nullable=False) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return self.id
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) pub_date = db.Column(db.DateTime) title = db.Column(db.String(120)) slug = db.Column(db.String(120), unique=True) text = db.Column(db.Text) def __init__(self, title, text, pub_date=None, slug=None): self.title = title self.text = text self.slug = (slug or title).replace(' ', '_') self.pub_date = (pub_date or datetime.utcnow()) def __repr__(self): return self.title def absolute_url(self): return url_for('blog.post_view', slug=self.slug)
class Recipe(db.Model): __tablename__ = 'recipe' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) description = db.Column(db.String(200)) num_of_servings = db.Column(db.Integer) cook_time = db.Column(db.Integer) directions = db.Column(db.String(1000)) is_publish = db.Column(db.Boolean(), default=False) created_at = db.Column(db.DateTime(), nullable=False,\ server_default=db.func.now()) update_at = db.Column(db.DateTime(), nullable=False,\ server_default=db.func.now(), onupdate=db.func.now()) user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
class Subscribe(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(150), nullable=False) def to_dict(self): return { 'id': self.id, 'email': self.email, } def __init__(self, email=None): self.email = email def serialize(self): return { 'id': self.id, 'email': self.email, }
class QuotaAttentionExp(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) topic = db.Column(db.String(20)) start_ts = db.Column(db.BigInteger(10, unsigned=True)) end_ts = db.Column(db.BigInteger(10, unsigned=True)) exp = db.Column( db.Text ) # exp={'media':x1, 'other':x2, 'opinion_leader':x3, 'oversea':x4, 'folk':x5} def __init__(self, topic, start_ts, end_ts, exp): self.topic = topic self.start_ts = start_ts self.end_ts = end_ts self.exp = exp @classmethod def _name(cls): return u'QuotaAttentionExp'
class Book(db.Model): """Book""" __tablename__ = 'book' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), unique=True) creat_time = db.Column(db.DateTime) update_time = db.Column(db.DateTime) bookrack_id = db.Column(db.Integer, db.ForeignKey('bookrack.id')) def __init__(self, name): self.name = name def __repr__(self): return f'<Book {self.name}>' def __str__(self): return f'<Book {self.name}>'
class Order(db.Model): __tablename__ = 'orders' orderID = db.Column(db.Integer(), primary_key=True) wasOrdered = db.Column(db.Boolean(), unique=False, default=False) wasAccepted = db.Column(db.Boolean(), default=False) dateOrdered = db.Column(db.DateTime(), server_default=func.now(), index=True) wasFulfilled = db.Column(db.Boolean(), unique=False, default=False) total = db.Column(db.Numeric(scale=2)) customer_ID = db.Column(db.Integer(), db.ForeignKey('customers.customerID')) payment_ID = db.Column(db.Integer(), db.ForeignKey('payments.paymentID')) shipper_ID = db.Column(db.Integer(), db.ForeignKey('shippers.shipperID')) supplier_ID = db.Column(db.Integer(), db.ForeignKey('suppliers.supplierID')) order_details = db.relationship('OrderDetails', backref='order')
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) title = db.Column(db.String(80)) subtitle = db.Column(db.String(80)) body = db.Column(db.Text) image = db.Column(db.String(125)) slug = db.Column(db.String(125), unique=True) publish_date = db.Column(db.DateTime) live = db.Column(db.Boolean) # tags have been disabled tags = db.relationship('Tag', secondary=tags_posts, backref=db.backref('posts', lazy='dynamic')) # get the whole image path @property def imgsrc(self): if self.image: return uploaded_images.url(self.image) else: return None # return the date in readable English @property def pubdate(self): return humanize.naturaltime(self.publish_date) def __init__(self, user, title, subtitle, body, slug, image=None, publish_date=None, live=True): self.user_id = user.id self.title = title self.subtitle = subtitle self.body = body self.image = image self.slug = slug if publish_date is None: self.publish_date = datetime.utcnow() self.live = live def __repr__(self): return '<Post %r>' % self.title
class Recipe(db.Model): __tablename__ = 'recipe' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) description = db.Column(db.String(200)) num_of_servings = db.Column(db.Integer) cook_time = db.Column(db.Integer) directions = db.Column(db.String(1000)) is_publish = db.Column(db.Boolean(), default=False) created_at = db.Column(db.DateTime(), nullable=False, server_default=db.func.now()) updated_at = db.Column(db.DateTime(), nullable=False, server_default=db.func.now(), onupdate=db.func.now()) user_id = db.Column(db.Integer(), db.ForeignKey("user.id")) def data(self): return { 'id': self.id, 'name': self.name, 'description': self.description, 'num_of_servings': self.num_of_servings, 'cook_time': self.cook_time, 'directions': self.directions, 'user_id': self.user_id } @classmethod def get_all_published(cls): return cls.query.filter_by(is_publish=True).all() @classmethod def get_by_id(cls, recipe_id): return cls.queru.filter_by(id=recipe_id).first() def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class LocationModel(db.Model): __tablename__ = "locations" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) capacity = db.Column(db.Integer) is_armap_available = db.Column(db.Boolean) def __init__(self, name, capacity=0, is_armap_available=False): self.name = name self.capacity = capacity self.is_armap_available = is_armap_available def json(self): json = { "id": self.id, "name": self.name, "capacity": self.capacity, "is_armap_available": self.is_armap_available } return json def activate_armap(self): self.is_armap_available = True @classmethod def find_location_by_id(cls, id): return cls.query.filter_by(id=id).first() @classmethod def find_location_by_name(cls, name): return cls.query.filter_by(name=name).first() # def find_all_locations(cls): # return {"location_results": list(map(lambda x: x.json(), cls.query.order_by(id).all()))} # # To-do here: the query order? def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class Recipe(db.Model): __tablename__ = 'recipe' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) description = db.Column(db.String(200)) num_of_serving = db.Column(db.Integer) cook_time = db.Column(db.Integer) directions = db.Column(db.String(1000)) is_publish = db.Column(db.Boolean(), default=False) created_at = db.Column(db.DateTime(), nullable=False, server_default=db.func.now()) updated_at = db.Column(db.DateTime(), nullable=False, server_default=db.func.now(), onupdate=db.func.now()) user_id = db.Column(db.Integer(), db.ForeignKey("user.id")) @classmethod def get_all_published(cls): return cls.query.filter_by(is_publish=True).all() @classmethod def get_all_by_user(cls, user_id, visibility='public'): if visibility == 'public': return cls.query.filter_by(user_id=user_id, is_publish=True).all() elif visibility == 'private': return cls.query.filter_by(user_id=user_id, is_publish=False).all() else: return cls.query.filter_by(user_id=user_id).all() @classmethod def get_by_id(cls, recipe_id): return cls.query.filter_by(id=recipe_id).first() def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class Deposit(db.Model): id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('company.id', ondelete='CASCADE'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False) status = db.Column(db.Boolean, default=True, nullable=False) amount = db.Column(db.Integer, nullable=False) datetime = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) account_id = db.Column(db.Integer, db.ForeignKey('payment_method.id', ondelete='CASCADE'), nullable=False) notes = db.Column(db.String(100)) user = db.relationship('User') account = db.relationship(PaymentMethod, backref='deposit', lazy=True)
class Episode(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) anime_id = db.Column(db.Integer) anime_name = db.Column(db.String(100)) season_id = db.Column(db.Integer, db.ForeignKey('season.id')) season_name = db.Column(db.String(100)) path = db.Column(db.String(100))
class Page(db.Model): id = db.Column(db.Integer, primary_key=True) number = db.Column(db.Integer) manga_id = db.Column(db.Integer) manga_name = db.Column(db.String(100)) chapter_id = db.Column(db.Integer, db.ForeignKey('chapter.id')) chapter_number = db.Column(db.Integer) path = db.Column(db.String(100))
class Patient(db.Model): cpf = db.Column(db.String(), primary_key=True) name = db.Column(db.StringField()) last_name = db.Column(db.StringField()) email = db.Column(db.StringField()) telefone = db.Column(db.StringField()) lat = db.Column(db.StringField()) long = db.Column(db.StringField())
class TimeTable(db.Model): id = db.Column(db.Integer, primary_key=True) mon = db.Column(db.String(100), nullable=False) tue = db.Column(db.String(100), nullable=False) wed = db.Column(db.String(100), nullable=False) thu = db.Column(db.String(100), nullable=False) fri = db.Column(db.String(100), nullable=False) sat = db.Column(db.String(100), nullable=False)
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(120), nullable=False, unique=True) email = db.Column(db.String(120), nullable=False, unique=True) password = db.Column(db.String(120), nullable=False) is_staff = db.Column(db.Integer, default=0, nullable=False) verified = db.Column(db.Boolean, default=False) token = db.Column(db.String(120), nullable=False, unique=True)
class ParseTaskInfo(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) task_id = db.Column(db.String(155), unique=True) filename = db.Column(db.String(200)) state = db.Column(db.String(30)) weight = db.Column(db.Integer, default=0) count = db.Column(db.Integer, default=0) date_add = db.Column(db.DateTime, default=datetime.now)
class NewsletterSubscription(db.Model): __tablename__ = 'newsletter_subscriptions' id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(300), nullable=False) last_name = db.Column(db.String(300), nullable=False) email = db.Column(db.String(700), nullable=False, unique=True) active = db.Column(db.Boolean(), default=False) unsubscription_reason = db.Column(db.String(700), default='') unsubscription_explanation = db.Column(db.String(3000), default='') unsubscription_date = db.Column(db.String(300), default='') date = db.Column(db.String(300), nullable=False) __mapper_args__ = { "order_by": id.desc() }
class Admin(db.Model,UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20)) password = db.Column(db.String(128)) blog_title = db.Column(db.String(60)) blog_sub_title = db.Column(db.String(100)) name = db.Column(db.String(30)) about = db.Column(db.Text)
class Expense(db.Model): id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('company.id', ondelete='CASCADE'), nullable=False) status = db.Column(db.Boolean, nullable=False, default=True) amount = db.Column(db.Integer, nullable=False) type = db.Column(db.Integer, db.ForeignKey('expense_type.id'), nullable=False) account = db.Column(db.Integer, db.ForeignKey('payment_method.id', ondelete='CASCADE'), nullable=False) datetime = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
class PaymentMethod(db.Model): id = db.Column(db.Integer, primary_key=True) company_id = db.Column(db.Integer, db.ForeignKey('company.id', ondelete='CASCADE')) status = db.Column(db.Boolean, default=True, index=True) name = db.Column(db.String(50), nullable=False, index=True) # bank name, paypal, stripe, Cash on delivery, etc account = db.Column(db.String(50)) holder_name = db.Column(db.String(50), nullable=False) api = db.Column(db.String(100))
class Receita(db.Model): __tablename__ = "Receita" id = db.Column(db.Integer, primary_key=True, autoincrement=True) nome = db.Column(db.String(100), nullable=False) descricao = db.Column(db.Text, nullable=True) adicionada_em = db.Column(db.DateTime, default=datetime.datetime.now) filhos = db.relationship("ReceitaIngrediente", back_populates="parente") def __repr__(self): return '<Receita {}>'.format(self.nome) def to_dict(self): return { "id":self.id, "nome":self.nome, "descricao":self.descricao }