class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(50), unique=True) username = db.Column(db.String(20), unique=True, 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) admin = db.Column(db.Boolean, default=False) posts = db.relationship('Post', backref="author", lazy=True) items = db.relationship('Item', backref="checker", lazy=True) active = db.Column(db.Boolean, default=False) 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 f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Location(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True, nullable=False) from_loc = db.relationship( 'Movement', backref='to', lazy=True, primaryjoin='Movement.from_location_id == Location.id') to_loc = db.relationship( 'Movement', backref='from', lazy=True, primaryjoin='Movement.to_location_id == Location.id')
class Product(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(200), nullable=False, unique=True) product_movement = db.relationship('ProductMovement', backref='product', lazy=True) def __repr__(self): return "{}".format(self.id)
class OrderDetail(db.Model): #订单详情 id = db.Column(db.Integer, primary_key=True) order_id = db.Column(db.String(30), index=True) goods_id = db.Column(db.Integer, db.ForeignKey('goods.id')) #goods_id = db.Column(db.Integer) goods_name = db.relationship('Goods', back_populates='order_id') goods_quantity = db.Column(db.Integer) goods_amount = db.Column(db.Float)
class Goods(db.Model): #商品信息表 id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), unique=True) price = db.Column(db.Float) order_id = db.relationship('OrderDetail', back_populates='goods_name') def __repr__(self): return '<Goods %r>' % self.name
class Supplyer(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) contact_number = db.Column(db.String, nullable=True) address = db.Column(db.Text, nullable=True) timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) items = db.relationship('Item', backref="distributor", lazy=True) def __repr__(self): return f"Post('{self.name}', '{self.contact_number}')"
class ProductMovement(db.Model): __tablename__ = 'product_movement' id = db.Column(db.Integer(), primary_key=True) product_id = db.Column(db.Integer(), db.ForeignKey('product.id'), nullable=False) from_location_id = db.Column(db.Integer(), db.ForeignKey('location.id'), nullable=True) to_location_id = db.Column(db.Integer(), db.ForeignKey('location.id'), nullable=True) from_location = db.relationship('Location', foreign_keys=[from_location_id]) to_location = db.relationship('Location', foreign_keys=[to_location_id]) quantity = db.Column(db.Integer) def __repr__(self): return "{}".format(self.id)
class Product(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True, nullable=False) moved_product = db.relationship('Movement', backref='item', lazy=True)