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 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)
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)
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())
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')
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)
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)
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)
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)
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)