Esempio n. 1
0
class Comment(db.Model):
    user_id = db.Column('user_id', db.Integer, db.ForeignKey('user.id'))
    post_id = db.Column('post_id',
                        db.Integer,
                        db.ForeignKey('post.id'),
                        primary_key=True)
    body = db.Column(db.String(50))
Esempio n. 2
0
class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True, nullable=False)
    company_id = db.Column(db.Integer,
                           db.ForeignKey('company.id'),
                           nullable=False)
    stock = db.Column(db.Integer, default=1)
    items = db.relationship('QuantityPerItem', backref='product')
Esempio n. 3
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    caption = db.Column(db.String(50))
    images = db.Column(db.String(100), nullable=False)
    comments = db.relationship('Comment', backref='post', lazy='dynamic')

    get_images = lambda self: ast.literal_eval(self.images)
Esempio n. 4
0
class StockManagment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    inventory_id = db.Column(db.Integer,
                             db.ForeignKey('inventory.id'),
                             primary_key=True)
    quantity = db.Column(db.Integer)
    company_id = db.Column(db.Integer,
                           db.ForeignKey('company.id'),
                           nullable=False)
Esempio n. 5
0
class QuantityPerItem(db.Model):
    '''This table store quantity required by each inventory to make a product'''

    inventory_id = db.Column(db.Integer,
                             db.ForeignKey('inventory.id'),
                             primary_key=True)
    product_id = db.Column(db.Integer,
                           db.ForeignKey('product.id'),
                           primary_key=True)
    quantity = db.Column(db.Integer, default=1)
Esempio n. 6
0
class QuantityPerPurchase(db.Model):
    '''This table store quantity of each inventory in a purchase'''

    inventory_id = db.Column(db.Integer,
                             db.ForeignKey('inventory.id'),
                             primary_key=True)
    unit_id = db.Column(db.Integer, db.ForeignKey('unit.id'), primary_key=True)
    purchase_id = db.Column(db.Integer,
                            db.ForeignKey('purchase.id'),
                            primary_key=True)
    quantity = db.Column(db.Integer, default=1)
    price = db.Column(db.Float())
Esempio n. 7
0
class Purchase(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    party_name = db.Column(db.String(50))
    current_date = db.Column(db.Date)
    suplier_date = db.Column(db.Date)
    invoice = db.Column(db.String(20), unique=True, nullable=False)
    items = db.relationship('QuantityPerPurchase', backref='purchase')
    company_id = db.Column(db.Integer,
                           db.ForeignKey('company.id'),
                           nullable=False)
Esempio n. 8
0
class Company(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True, nullable=False)
    number = db.Column(db.Integer(), unique=True)
    email = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(60), nullable=False)
Esempio n. 9
0
class Unit(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True, nullable=False)
    company_id = db.Column(db.Integer,
                           db.ForeignKey('company.id'),
                           nullable=False)
Esempio n. 10
0
class User(db.Model, UserMixin):
        __searchable__ = ['username', 'name']

        id = db.Column(db.Integer, primary_key=True)
        name = db.Column(db.String(50), nullable=False)
        username = db.Column(db.String(80), unique=True, nullable=False)
        avatar = db.Column(db.String(120), nullable = False, default = 'default.svg')
        email = db.Column(db.String(120), unique=True, nullable=False)
        password = db.Column(db.String(200), unique=True, nullable=False)
        is_confirmed = db.Column(db.Boolean, default=False)
        posts = db.relationship('Post', backref='user', lazy='dynamic')
        comments = db.relationship('Comment', backref='user', lazy='dynamic')
        posts_liked = db.relationship('Post', secondary=likes, backref='user_liked', lazy='dynamic')
        followed = db.relationship('Follow', foreign_keys=[Follow.follower_id],
                                   backref=db.backref('follower', lazy='joined'),
                                   lazy='dynamic', cascade='all, delete-orphan')
        followers = db.relationship('Follow', foreign_keys=[Follow.followed_id],
                                   backref=db.backref('followed', lazy='joined'),
                                   lazy='dynamic', cascade='all, delete-orphan')

        def set_password(self, password):
            self.password = generate_password_hash(password)

        def check_password(self, password):
            return check_password_hash(self.password, password)

        def get_serializer_token(self, expires_sec=600, salt='default'):
            s = Serializer(current_app.config['SECRET_KEY'], expires_sec, salt=salt)
            return s.dumps({'user_id': self.id}).decode('utf-8')

        @staticmethod
        def verify_serializer_token(token, salt='default'):
            s = Serializer(current_app.config['SECRET_KEY'], salt=salt)
            try:
             user_id = s.loads(token)['user_id']
            except:
             return None
            return User.query.get(user_id)

        def is_following(self, user):
            return self.followed.filter_by(followed_id=user.id).first() is not None

        def is_followed_by(self, user):
            return self.followers.filter_by(follower_id=user_id).first() is not None

        def follow(self, user):
            if not self.is_following(user):
                f = Follow(follower=self, followed=user)
                db.session.add(f)

        def unfollow(self, user):
            f = self.followed.filter_by(followed_id=user.id).first()
            if f :
                db.session.delete(f)

        @property
        def self_follow(self):
            self.follow(self)

        @property
        def followed_posts(self):
            return Post.query.join(Follow, Follow.followed_id == Post.user_id)\
                    .filter(Follow.follower_id == self.id)

        @property
        def all_followed(self):
            return [ f.followed for f in self.followed.filter(Follow.followed_id != self.id).all() ]

        @property
        def all_followers(self):
            return [ f.follower for f in self.followers.filter(Follow.follower_id != self.id).all() ]
Esempio n. 11
0
class Follow(db.Model):
    followed_id = db.Column('followed_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)
    follower_id = db.Column('follower_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)
Esempio n. 12
0
import ast
from app.extinsions import db

likes = db.Table('likes',
                 db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
                 db.Column('post_id', db.Integer, db.ForeignKey('post.id')))


class Comment(db.Model):
    user_id = db.Column('user_id', db.Integer, db.ForeignKey('user.id'))
    post_id = db.Column('post_id',
                        db.Integer,
                        db.ForeignKey('post.id'),
                        primary_key=True)
    body = db.Column(db.String(50))


class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    caption = db.Column(db.String(50))
    images = db.Column(db.String(100), nullable=False)
    comments = db.relationship('Comment', backref='post', lazy='dynamic')

    get_images = lambda self: ast.literal_eval(self.images)