I have 2 tables with the same column structure.
The script pulls from 2 different json sources with slightly different keys.
My Item class identifies the source and then parses the data.
In my Item class I want to be able to change the __tablename__ based on the data source.
Is this possible or do I need to write a separate class for each data source?
Thanks,
Code:
Base = declarative_base()
class Item(Base):
__tablename__ = 'products'
timestamp = Column(TIMESTAMP)
itemid = Column(String, primary_key=True, index=True, unique=True)
name = Column(String)
def __init__(self, item):
if type(item) == Product_A:
self.__tablename__ = "A_products"
# Parse Data
elif type(item) == Product_B:
self.__tablename__ = "B_products"
# Parse Data