2

I am building a flask application and using flask-sqlalchemy. I have two classes defined as follows:

class RawMaterials(db.Model):
    __tablename__ = 'rawMaterials'
    id = db.Column(db.Integer, autoincrement=True)
    stockCode = db.Column(db.String(32),primary_key=True)
    altKey = db.Column(db.String(120))
    description = db.Column(db.String(120))
    longDescription = db.Column(db.String(120))
    cost = db.Column(db.Float)
    warehouse = db.Column(db.String(120))
    supplier = db.Column(db.String(120))
    supplierDescription = db.Column(db.String(120))

class TempRawMaterials(db.Model):
    __tablename__ = 'tempRawMaterials'
    id = db.Column(db.Integer, autoincrement=True)
    stockCode = db.Column(db.String(32), primary_key=True)
    altKey = db.Column(db.String(120), nullable=False)
    description = db.Column(db.String(120), nullable=False)
    longDescription = db.Column(db.String(120))
    cost = db.Column(db.Float)
    warehouse = db.Column(db.String(120))
    supplier = db.Column(db.String(120), nullable=False)
    supplierDescription = db.Column(db.String(120))

I would like to create another class and would like to auto-populate it whenever the two tables defined above gets new data.

class AllRawMaterials(db.Model):
    __tablename__ = "allRawMaterials"
    id = db.Column(db.Integer, autoincrement=True)
    stockCode = db.Column(db.String(32),primary_key=True) # this column will contain stockcodes from both 
                                                          # the tables

Also stockCode column from both the tables are/will be always mutually exclusive.

Kartikeya Sharma
  • 1,335
  • 1
  • 10
  • 22

0 Answers0