Ejemplo n.º 1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(250), unique=True, nullable=False)
    first_name = db.Column(db.String(255), nullable=False)
    last_name = db.Column(db.String(255), nullable=False)
    password = db.Column(db.String(60), nullable=False)
    isAdmin = db.Column(db.Boolean, default=False)
    isSuperUser = db.Column(db.Boolean, default=False)
    requests = db.relationship('Request', backref='user', lazy=True)
    special_requests = db.relationship('SpecialRequest',
                                       backref='user',
                                       lazy=True)
    # bills = db.relationship('Bill', backref='user', lazy=True)
    picture = db.Column(db.String(60), nullable=False, default='default.jpg')

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return str({
            'email': self.email,
            'name': self.first_name + " " + self.last_name,
        })
Ejemplo n.º 2
0
class Post(db.Model):
    __tablename__ = "posts"

    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

    user = db.relationship('User', foreign_keys=user_id) #campo de relacionamento | 

    def __init__(self, content, user_id):
        self.content = content
        self.user_id = user_id

    
     def Follow(db.Model):
        __tablename__ = "follow"

        id = db.Column(db.Integer, primary_key=True)
        user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
        follower_id = db.Column(db.Integer, db.ForeignKey('users.id'))

        user = db.relationship('User', foreign_keys=user_id)
        follower = db.relationship('User', foreign_keys=follower_id)
        
        
Ejemplo n.º 3
0
class Answer(db.Model):
    __tablename__ = 'answer'
    id = db.Column(db.Integer, primary_key=True, unique=True, nullable=False)
    content = db.Column(db.Text, nullable=False)
    question_id = db.Column(db.Integer, db.ForeignKey('question.message_id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    question = db.relationship('Question', backref='answere')
    user = db.relationship('User', backref='answere')
Ejemplo n.º 4
0
class Follow(db.Model):
         __tablename__ ="follow"

         id = db.Column(db.Integer, primary_key=True)
         user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
         follower_id = db.Column(db.Integer, db.ForeignKey('users.id'))

         user = db.relationship('User', foreign_keys=user_id)
         follower = db.relationship('User', foreign_keys=follower_id)
Ejemplo n.º 5
0
class Shops(db.Model):
    __tablename__ = "shops"
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    shop_name = db.Column(db.String(64), nullable=False, unique=True)

    products = db.relationship('Products',
                               backref='store',
                               lazy='dynamic',
                               cascade="save-update, merge, delete")
    orders = db.relationship('Orders',
                             backref='store',
                             lazy='dynamic',
                             cascade="save-update, merge, delete")

    def __repr__(self):
        return '<Shop {}>'.format(self.shop_name)

    def owned_items(self):
        product_ids = [
            product.id
            for product in Products.query.filter_by(shop_id=self.id).all()
        ]
        order_ids = [
            order.id
            for order in Orders.query.filter_by(shop_id=self.id).all()
        ]
        p_items = LineItems.query.filter(
            LineItems.product_id.in_(product_ids)).all()
        items = LineItems.query.filter(LineItems.order_id.in_(order_ids)).all()

        for i in p_items:
            is_duplicated = False
            for _i in items:
                if i.id == _i.id:
                    is_duplicated = True
                    break
            if not is_duplicated:
                items.append(i)

        return items

    def owned_item_ids(self):
        return [item.id for item in self.owned_items()]

    @staticmethod
    def create_shop(name, owner):
        shop = Shops.query.filter(Shops.shop_name == name).first()
        if shop is not None:
            return False

        shop = Shops(shop_name=name, user_id=owner.id)
        db.session.add(shop)
        db.session.commit()
        return shop.id
Ejemplo n.º 6
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(191), unique=True)
    password = db.Column(db.String(191))
    username = db.Column(db.String(191))
    full_name = db.Column(db.String(191))
    phone = db.Column(db.String(191))
    avatar = db.Column(db.String(191))
    socketio_session_id = db.Column(db.String(191))
    active = db.Column(db.Boolean(), default=True)
    created_at = db.Column(db.DateTime(), default=datetime.utcnow())
    verified_at = db.Column(db.DateTime())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
    permissions = db.relationship('Permission',
                                  secondary=permissions_users,
                                  backref=db.backref('users', lazy='dynamic'))

    def get_password_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_password_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def has_role(self, role_name):
        role = Role.query.filter_by(name=role_name).first()
        return True if role in self.roles else False

    def has_permission(self, permission_name):
        p = Permission.query.filter_by(name=permission_name).first()
        if p in self.permissions:
            return True
        for role in self.roles:
            if p in role.permissions:
                return True
        return False

    def assign_role(self, role_name):
        r = Role.query.filter_by(name=role_name).first()
        self.roles.append(r)

    def assign_permission(self, permission_name):
        p = Permission.query.filter_by(name=permission_name).first()
        self.permissions.append(p)
Ejemplo n.º 7
0
class User(UserMixin, db.Model):
    #General Info
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    avatar = db.Column(db.String(100))
    password_hash = db.Column(db.String(128))

    #Post Relationship
    posts = db.relationship('Post', backref='author', lazy='dynamic')

    #Follower Relationship
    followed = db.relationship(
        'User', secondary=followers,
        primaryjoin=(followers.c.follower_id == id),
        secondaryjoin=(followers.c.followed_id == id),
        backref=db.backref('followers', lazy='dynamic'), lazy='dynamic')

    def follow(self, user):
        if not self.is_following(user):
            self.followed.append(user)

    def unfollow(self, user):
        if self.is_following(user):
            self.followed.remove(user)

    def is_following(self, user):
        return self.followed.filter(
            followers.c.followed_id == user.id).count() > 0

    def followed_posts(self):
        followed = Post.query.join(
            followers, (followers.c.followed_id == Post.user_id)).filter(
                followers.c.follower_id == self.id)
        own = Post.query.filter_by(user_id=self.id)
        return followed.union(own).order_by(Post.timestamp.desc())
    
    #General info
    about_me = db.Column(db.String(140))
    last_seen = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return '<User {}>'.format(self.username)
    
    #Set and check password
    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)
Ejemplo n.º 8
0
class Detalle(db.Model):
    __tablename__ = 'Detalle'
    id = db.Column(db.Integer(), primary_key=True)
    codProducto = db.Column(db.Integer,
                            db.ForeignKey('Productos.Codigo'),
                            nullable=False)
    codingreso = db.Column(db.Integer, db.ForeignKey('Ingreso.cod_ingreso'))
    codsalida = db.Column(db.Integer, db.ForeignKey('salida.Codigo'))
    Docenas = db.Column(db.Integer, nullable=False)
    Unidades = db.Column(db.Integer, nullable=False)
    #relaciones
    fk_producto = db.relationship("productos")
    fk_Ingreso = db.relationship("ingreso")
    fk_Salida = db.relationship("Salida")
Ejemplo n.º 9
0
class Project(Base):
    __tablename__ = "project"
    project_name = db.Column(db.String(32),
                             nullable=False,
                             default="",
                             unique=True)
    project_desc = db.Column(db.String(500), nullable=False, default="")

    interface = db.relationship("Interfaces",
                                backref="project_interface",
                                lazy='dynamic')
    case = db.relationship('Case', backref="project_case", lazy='dynamic')
    ucase = db.relationship("UICase", backref='project_ucase', lazy='dynamic')
    method = db.relationship("UMethod",
                             backref='project_method',
                             lazy='dynamic')
    debugtalk = db.relationship("DebugTalks",
                                backref='project_debugtalk',
                                uselist=False)

    def __init__(self, name, desc):
        self.project_desc = desc
        self.project_name = name

    def __repr__(self):
        return f"project_name:{self.project_name}"

    @classmethod
    def assertIdExisted(cls, id):
        p = cls.query.get(id)
        if not p:
            handelAbort(f"projectId {id} 不存在或删除")
        return p

    @classmethod
    def assertName(cle, name):
        res = cle.query.filter_by(project_name=name, status=1).first()
        if res:
            handelAbort("projectName 重复!")

    def delete(self):
        self.status = self.DELETE_STATUS
        # 级联修改状态
        for interface in self.interfaces_records:
            interface.status = self.DELETE_STATUS
            for case in interface.case_records:
                case.status = self.DELETE_STATUS
        db.session.commit()
Ejemplo n.º 10
0
class Movie(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    rating = db.Column(db.Float, nullable=False, default=0)
    image = db.Column(db.String(90), nullable=False, default='default_img.png')
    like = db.relationship('User',
                           secondary=likes,
                           backref=db.backref('like', lazy='dynamic'))
    Genre = db.Column(db.String(100))
    Action = db.Column(db.Integer, nullable=False)
    Adventure = db.Column(db.Integer, nullable=False)
    Animation = db.Column(db.Integer, nullable=False)
    Comedy = db.Column(db.Integer, nullable=False)
    Crime = db.Column(db.Integer, nullable=False)
    Documentary = db.Column(db.Integer, nullable=False)
    Drama = db.Column(db.Integer, nullable=False)
    Family = db.Column(db.Integer, nullable=False)
    Fantasy = db.Column(db.Integer, nullable=False)
    Foreign = db.Column(db.Integer, nullable=False)
    History = db.Column(db.Integer, nullable=False)
    Horror = db.Column(db.Integer, nullable=False)
    Music = db.Column(db.Integer, nullable=False)
    Mystery = db.Column(db.Integer, nullable=False)
    Romance = db.Column(db.Integer, nullable=False)
    Science_Fiction = db.Column(db.Integer, nullable=False)
    Tv_Movie = db.Column(db.Integer, nullable=False)
    Thriller = db.Column(db.Integer, nullable=False)
    War = db.Column(db.Integer, nullable=False)
    Western = db.Column(db.Integer, nullable=False)

    def __repr__(self):
        return f"Movie:{self.name},rating:{self.rating}"
Ejemplo n.º 11
0
class Interfaces(Base):
    __tablename__ = "interfaces"
    interface_name = db.Column(db.String(32), nullable=False, comment="接口名")
    interface_desc = db.Column(db.String(500), default="", comment='描述')
    tester = db.Column(db.String(32), comment='测试人')

    project_id = db.Column(db.INT, db.ForeignKey("project.id"))
    case = db.relationship("Case", backref="interface", lazy="dynamic")

    def __init__(self, name, desc, pid):
        self.interface_desc = desc
        self.interface_name = name
        self.project_id = pid

    @classmethod
    def assertName(cle, name):
        res = cle.query.filter_by(interface_name=name).first()
        if res:
            handelAbort("interface_name 重复!")

    @classmethod
    def assertIdExisted(cls, id):
        p = cls.query.get(id)
        if not p or p.status == 0:
            handelAbort("interface 不存在或删除")

    def delete(self):
        self.status = self.DELETE_STATUS
        try:
            for case in self.case_records:
                case.status = self.DELETE_STATUS
            db.session.commit()
        except Exception as e:
            log.exception(e)
            db.session.rollback()
Ejemplo n.º 12
0
class Cidades(db.Model):
    __tablename__ = 'cidades'
    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(100))
    idmicroregiao = db.Column(db.Integer, db.ForeignKey('microregiao.id'))
    iduf = db.Column(db.Integer, db.ForeignKey('uf.id'))
    microregiao = db.relationship("MicroRegiao")
Ejemplo n.º 13
0
class users(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(255), unique=True, nullable=False)
    email = db.Column(db.String(255), unique=True, nullable=False)
    hash = db.Column(db.String(255), nullable=False)
    gender = db.Column(db.String(22), nullable=False)
    job = db.Column(db.String(255), nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default='avatar.png')
    createdOn = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    todo_items = db.relationship('todo_items', backref='author', lazy=True)

    def getResetToken(self, expires_sec=1800):
        s = serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verifyResetToken(token):
        s = serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return users.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', {self.email}, '{self.gender}', '{self.job}', '{self.createdOn}')"
Ejemplo n.º 14
0
class Role(db.Model):
    __tablename__ = 'roles'
    role_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    default = db.Column(db.Boolean, default=False, index=True)
    permissions = db.Column(db.Integer, nullable=False)
    users = db.relationship("User", backref="role", lazy="dynamic")

    def __str__(self):
        return "<table roles %s %s>" % (self.role_id, self.name)

    __repr__ = __str__

    @staticmethod
    def manage_roles():
        '''
		管理角色权限,可在这里修改每种角色的权限, 同时更新到数据库使系统生效
		'''
        role_permissions_dict = {
            "User": (Permission.FOLLOW | Permission.COMMENT
                     | Permission.WRITE_ARTICLES, True),
            "Moderatoe":
            (Permission.FOLLOW | Permission.COMMENT | Permission.WRITE_ARTICLES
             | Permission.MODERATE_COMMENTS, False),
            'Administrator': (0xff, False)
        }

        for role_name in role_permissions_dict.iterkeys():
            role = Role.query.filter_by(name=role_name).first()
            if not role:
                role = Role(name=role_name)
            role.permissions = role_permissions_dict[role_name][0]
            role.default = role_permissions_dict[role_name][1]
            db.session.add(role)
        db.session.commit()
Ejemplo n.º 15
0
class User(db.Model, UserMixin):
    """class that provides User entity with relation to Tittr as author"""
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(25), unique=True, nullable=False)
    email = db.Column(db.String(125), unique=True, nullable=False)
    image_file = db.Column(db.String(100),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(100), nullable=False)
    posts = db.relationship('Tittr', backref='author', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        """reset token generator"""
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        """reset token verification"""
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
Ejemplo n.º 16
0
class UF(db.Model):
    __tablename__ = 'uf'
    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(100))
    sigla = db.Column(db.String(2))
    idregiao = db.Column(db.Integer, db.ForeignKey('regiao.id'))
    regiao = db.relationship("Regiao")
Ejemplo n.º 17
0
class User(db.Model,UserMixin):
    id=db.Column(db.Integer,primary_key=True)
    first_name = db.Column( db.String(20),nullable=False)
    last_name = db.Column( db.String(20),nullable=False)
    email=db.Column(db.String(120),unique=True,nullable=False)
    image_file=db.Column(db.String(20),nullable=False,default="default.jpg")
    password=db.Column(db.String(60),nullable=False)
    posts = db.relationship('Post',backref='author',lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')
    
    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id'] 
        except:
            return None
        return User.query.get(user_id)   
    
    
    def __repr__(self):
        return "User('{} {}','{}','{}')".format(self.first_name,self.last_name,self.email,self.image_file) 
Ejemplo n.º 18
0
class Article(db.Model):
    __tablename__ = "articls"

    articls_id = db.Column(db.INT, primary_key=True, autoincrement=True)
    articls_title = db.Column(db.String(300), unique=False)
    articls_desc = db.Column(db.String(64), nullable=True)
    articls_contents = db.Column(db.Text, unique=False)
    articls_posttime = db.Column(db.DateTime)
    articls_category = db.Column(db.String(99), unique=False, default=None)
    articls_headimg = db.Column(db.String(99), unique=False, default=None)
    # user_id = db.Column(db.INTEGER, db.ForeignKey('admin_user.user_id'))  # 关联用户userID
    tag_id = db.Column(db.INTEGER, db.ForeignKey('tag.id'))  # 关联标签ID
    category_id =  db.Column(db.INTEGER, db.ForeignKey('category.id'))  # 关联分类ID
    comment = db.relationship('Comment', backref='comment', lazy='dynamic')
    tag = db.relationship('Tag', backref='tag')
    category = db.relationship('Category', backref='status')
Ejemplo n.º 19
0
class Products(db.Model):
    __tablename__ = "products"
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    shop_id = db.Column(db.Integer, db.ForeignKey('shops.id'), nullable=False)
    product_name = db.Column(db.String(64), nullable=False)
    price = db.Column(db.Float, nullable=False, index=True)
    cost = db.Column(db.Float, nullable=False, index=True)

    line_items = db.relationship('LineItems',
                                 backref='type',
                                 lazy='dynamic',
                                 cascade="save-update, merge, delete")

    def __repr__(self):
        return '<Products {}>'.format(self.product_name)

    @staticmethod
    def create_product(name, store, price, cost):
        product = Products.query.filter(Products.shop_id == store.id).filter(
            Products.product_name == name).first()
        if product is not None:
            return False

        product = Products(product_name=name,
                           shop_id=store.id,
                           price=price,
                           cost=cost)
        db.session.add(product)
        db.session.commit()
        return product.id
Ejemplo n.º 20
0
class User(db.Model):
    __tablename__ = "blog_users"

    # id是主键db.Column是字段名, db.INT是数据类型
    user_id = db.Column(db.INT, primary_key=True, autoincrement=True)
    user_name = db.Column(db.String(20), unique=True)
    user_password = db.Column(db.String(10), unique=False)
    user_nickname = db.Column(db.String(40), unique=True, default=None)
    user_headimg = db.Column(db.String(99), unique=False, default=None)
    user_tel = db.Column(db.String(11), unique=False, default=None)
    user_email = db.Column(db.String(99), unique=True)
    user_sex = db.Column(db.Boolean, default=1)
    create_time = db.Column(db.DateTime, nullable=True, default=datetime.now)

    c = db.relationship('Comment', backref='user', lazy='dynamic')
    # r = db.relationship('Article', backref='user', lazy='dynamic')
    # s = db.relationship('Status', backref='user', lazy='dynamic')

    def __init__(self, user_name, user_password, user_nickname, user_headimg, user_tel, user_email, user_sex,
                 create_time):
        self.user_name = user_name
        self.user_password = user_password
        self.user_nickname = user_nickname
        self.user_headimg = user_headimg
        self.user_tel = user_tel
        self.user_email = user_email
        self.user_sex = user_sex
        self.create_time = create_time
Ejemplo n.º 21
0
class Orders(db.Model):
    __tablename__ = "orders"
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    shop_id = db.Column(db.Integer, db.ForeignKey('shops.id'), nullable=False)

    # instead of storing these attributes in the database, we will calculate them in run time, to reduce the number
    # of changes made to the database (else, when one makes a change to line items, products, etc, these values all
    # need to be recalculated

    # total_price = db.Column(db.Float, nullable=False, index=True)
    # total_cost = db.Column(db.Float, nullable=False, index=True)
    # total_income = db.Column(db.Float, nullable=False, index=True)

    lineItems = db.relationship('LineItems',
                                backref='bill',
                                lazy='dynamic',
                                cascade="save-update, merge, delete")

    def __repr__(self):
        return '<Order {}>'.format(self.id)

    @staticmethod
    def create_order(store):
        order = Orders(shop_id=store.id)
        db.session.add(order)
        db.session.commit()
        return order.id
Ejemplo n.º 22
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))
    posts = db.relationship('Post', backref='author', lazy='dynamic')
    about_me = db.Column(db.String(140))
    last_seen = db.Column(db.DateTime, default=datetime.utcnow)
    followed = db.relationship('User',
                               secondary=followers,
                               primaryjoin=(followers.c.follower_id == id),
                               secondaryjoin=(followers.c.followed_id == id),
                               backref=db.backref('followers', lazy='dynamic'),
                               lazy='dynamic')

    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)

    def avatar(self, size):
        digest = md5(self.email.lower().encode('utf-8')).hexdigest()
        return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format(
            digest, size)

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def follow(self, user):
        if not self.is_following(user):
            self.followed.append(user)

    def unfollow(self, user):
        if self.is_following(user):
            self.followed.remove(user)

    def is_following(self, user):
        return self.followed.filter(
            followers.c.followed_id == user.id).count() > 0

    def followed_posts(self):
        followed = Post.query.join(
            followers, (followers.c.followed_id == Post.user_id)).filter(
                followers.c.follower_id == self.id)
        own = Post.query.filter_by(user_id=self.id)
        return followed.union(own).order_by(Post.timestamp.desc())
Ejemplo n.º 23
0
class Role(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    users = db.relationship('User', backref='role')

    def __repr__(self):
        return '<Role %r>' % self.name
Ejemplo n.º 24
0
class Category(db.Model):
    __tablename__ = "category"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    category_title= db.Column(db.String(300), unique=False)
    create_time = db.Column(db.DateTime, nullable=True, default=datetime.now)
    Article = db.relationship('Article',  lazy='dynamic')
    info = db.Column(db.String(255), unique=False)
Ejemplo n.º 25
0
class Pessoa(db.Model):
    __tablename__ = 'pessoa'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(30))
    nome = db.Column(db.String(70))
    razaosocial = db.Column(db.String(70))
    tipopessoa = db.Column(db.String(2), nullable=False)
    password = db.Column(db.String(200))
    email = db.Column(db.String(60))

    refeicao = db.relationship('Refeicao', back_populates="pessoa")
    cliente = db.relationship("Cliente", back_populates="pessoa")
    atleta = db.relationship("Atleta", back_populates="pessoa")
    #mensagewhatsapp = db.relationship("MensageWhatsApp", back_populates="pessoa")
    create_on = db.Column(db.DateTime, default=datetime.datetime.now())
    phone = db.Column(db.String(20))
    profilenamephone = db.Column(db.String(20))
Ejemplo n.º 26
0
class Refeicao(db.Model):
    __tablename__ = 'refeicao'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    descricao = db.Column(db.String(50), nullable=False)
    hora = db.Column(db.Time)
    mostrar = db.Column(db.String(1))
    idpessoa = db.Column(db.Integer,
                         db.ForeignKey('pessoa.id', ondelete='CASCADE'))
    pessoa = db.relationship("Pessoa", back_populates="refeicao")
Ejemplo n.º 27
0
class Metaatleta(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    descricao = db.Column(db.String(50), nullable=False)
    create_on = db.Column(db.DateTime, default=datetime.datetime.now())
    pesoinicial = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    pesofinal = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    percentual_gordura = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    nivelatividade = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    # 0-Harris Benedict Original 1-Harris Benedict Revisada 2-Mifflin St Jeor 3-Katch-McArdle
    frmharrisbenedictoriginal = db.Column(db.String(1), nullable=False)
    frmharrisbenedictrevisada = db.Column(db.String(1), nullable=False)
    frmmifflin = db.Column(db.String(1), nullable=False)
    frmkatch = db.Column(db.String(1), nullable=False)
    valtmb = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=0))
    valgcd = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=0))
    # P-perda de peso G-ganho de peso
    tipometa = db.Column(db.String(1), nullable=False)
    valtotkclmeta = db.Column(db.NUMERIC(precision=8, asdecimal=False,
                                         scale=0))
    valtotkclexercicio = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=0))
    valalvocalorico = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=0))

    # Proteina
    percproteina = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valkcalproteina = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valgramasproteina = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valgrkgproteina = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    # Carboidrato
    perccarb = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valkcalcarb = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valgramascarbo = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valgrkgcarbo = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    # Gordura
    percfat = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valkcalfat = db.Column(db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valgramasgordura = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    valgrkggordura = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
    # A-Aberto F-Fechada
    status = db.Column(db.String(1), nullable=False)
    idatleta = db.Column(db.Integer,
                         db.ForeignKey('atleta.id', ondelete='CASCADE'))
    atleta = db.relationship("Atleta", back_populates="metaatleta")
    totaldiasprevisto = db.Column(db.Integer)
    dataprevisaofinal = db.Column(db.DateTime)
    datafinalizada = db.Column(db.DateTime)
    pesofinalizado = db.Column(
        db.NUMERIC(precision=8, asdecimal=False, scale=2))
Ejemplo n.º 28
0
class Tag(db.Model):
    __tablename__ = "tag"
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    name = db.Column(db.String(32), nullable=False)
    desc = db.Column(db.String(64), nullable=True)
    create_time = db.Column(db.DateTime, nullable=True, default=datetime.now)
    Article = db.relationship('Article',  lazy='dynamic')

    def __repr__(self):
        return '<User %r>' % self.name
Ejemplo n.º 29
0
class Conversation(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(191))
    started_by = db.Column(db.Integer)
    started_with = db.Column(db.Integer)
    created_at = db.Column(db.DateTime(), default=datetime.utcnow())
    updated_at = db.Column(db.DateTime())
    messages = db.relationship('Message',
                               backref='conversation',
                               lazy='dynamic')
Ejemplo n.º 30
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    picture = db.Column(db.String(60), nullable=False, default='default.jpg')
    stocks = db.relationship('Stock', backref='category', lazy=True)

    def __repr__(self):
        return str({
            'categoryName': self.name,
        })