Files
KCGL/inventory-backend/app/models/material.py

32 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#material.py
from app.extensions import db
from datetime import datetime
class MaterialBase(db.Model):
__tablename__ = 'material_base'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False) # 名称
category = db.Column(db.String(100)) # 类别
material_type = db.Column(db.String(100)) # 类型
spec_model = db.Column(db.String(255)) # 规格型号
unit = db.Column(db.String(50)) # 计量单位
visibility_level = db.Column(db.Integer, default=0) # 信息可见等级
manual_link = db.Column(db.Text) # 通用说明书
product_image = db.Column(db.Text) # 通用产品图
is_enabled = db.Column(db.Boolean, default=True) # 是否启用
# 【核心关联】
# 这里定义了反向关系lazy='dynamic' 允许我们后续做 count() 查询
# cascade='all, delete-orphan' 并不是在这里用的,因为我们是手动控制逻辑
stock_buys = db.relationship('StockBuy', back_populates='material', lazy='dynamic')
def to_dict(self):
return {
'id': self.id,
'name': self.name,
'category': self.category,
'material_type': self.material_type,
'spec_model': self.spec_model,
'unit': self.unit
}