Python 3.x 如何将对象反序列化为与python有关系的表

Python 3.x 如何将对象反序列化为与python有关系的表,python-3.x,sqlalchemy,Python 3.x,Sqlalchemy,我创建了一个包含大量关系的表,并希望将对象(或dict)上载(大容量插入)到表中。这里有一个简单的方案,主要目的是简单地将包含内部内容的dict上传到此表。现在,我创建了一组集合,将内容上载到其他(不是ecomapp_产品)表,然后将其他映射上载到主表(ecomapp_产品)。使用反序列化程序是否可以更简单?我已经创建了sqlalchemy映射来实现这一点,但我不知道接下来要做什么 # coding=utf-8 from sqlalchemy import (Column, BigIntege

我创建了一个包含大量关系的表,并希望将对象(或dict)上载(大容量插入)到表中。这里有一个简单的方案,主要目的是简单地将包含内部内容的dict上传到此表。现在,我创建了一组集合,将内容上载到其他(不是ecomapp_产品)表,然后将其他映射上载到主表(ecomapp_产品)。使用反序列化程序是否可以更简单?我已经创建了sqlalchemy映射来实现这一点,但我不知道接下来要做什么

# coding=utf-8

from sqlalchemy import (Column, BigInteger, Integer, String,
                        Boolean, DateTime, ForeignKey, Date)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship

Base = declarative_base()


class Brand(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_brand"
    id = Column(Integer, primary_key=True)
    title = Column(String(100))
    slug = Column(String(1500))


class Group(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_group"
    id = Column(Integer, primary_key=True)
    title = Column(String(100))
    en_title = Column(String(100))
    slug = Column(String(1500))


class Category(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_category"
    id = Column(Integer, primary_key=True)
    title = Column(String(100))
    en_title = Column(String(100))
    slug = Column(String(1500))
    group_id = Column(Integer, ForeignKey("ecomapp_group.id"))

    group = relationship("Group", foreign_keys=[group_id])


class Gender(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_gender"
    id = Column(Integer, primary_key=True)
    title = Column(String(100))


class Shop(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_shop"
    id = Column(Integer, primary_key=True)
    title = Column(String(100))
    slug = Column(String(1500))
    code = Column(String(100))           # для этих
    sale = Column(Integer)               # колонок нужны
    url = Column(String(1500))           # дефолтные значения
    freeship_minprice = Column(Integer)  # (пустые строки и 0) 100000 для минпрайса


class Sport(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_sport"
    id = Column(Integer, primary_key=True)
    title = Column(String(100))


class Buttons(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_buttonsmain"
    id = Column(Integer, primary_key=True)
    title = Column(String(100))
    priority = Column(Integer)
    sex_id = Column(Integer, ForeignKey("ecomapp_gender.id"))


class UniqueId(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_unique_id"
    id = Column(Integer, primary_key=True)
    url = Column(String(1500))
    unique_id = Column(Integer, ForeignKey("ecomapp_product.id"))
    unique = relationship("Unique", foreign_keys=[unique_id])


class Product(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_product"
    id = Column(Integer, primary_key=True)
    title = Column(String(1500))
    description = Column(String(1500))
    oldprice = Column(Integer)
    price = Column(Integer)
    discount = Column(Integer)
    slug = Column(String(1500))
    url = Column(String(1500))
    picture = Column(String(1500))
    freeship = Column(Boolean)
    on_main = Column(Boolean)
    time = Column(Date)
    model = Column(String(300))
    in_stock = Column(Boolean)
    brand_id = Column(Integer, ForeignKey("ecomapp_brand.id"))
    category_id = Column(Integer, ForeignKey("ecomapp_category.id"))
    sex_id = Column(Integer, ForeignKey("ecomapp_gender.id"))
    shop_id = Column(Integer, ForeignKey("ecomapp_shop.id"))
    sport_id = Column(Integer, ForeignKey("ecomapp_sport.id"))
    rating = Column(Integer)
    clicks = Column(Integer)
    views = Column(Integer)

    brand = relationship("Brand", foreign_keys=[brand_id])
    category = relationship("Category", foreign_keys=[category_id])
    sex = relationship("Sex", foreign_keys=[sex_id])
    shop = relationship("Shop", foreign_keys=[shop_id])
    sport = relationship("Sport", foreign_keys=[sport_id])


class Size(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_size"
    id = Column(Integer, primary_key=True)
    ru_title = Column(String(10))
    eu_title = Column(String(10))
    uk_title = Column(String(10))
    us_title = Column(String(10))
    fr_title = Column(String(10))


class Productsize(Base):
    def __init__(self):
        pass

    __tablename__ = "ecomapp_productsize"
    id = Column(Integer, primary_key=True)
    product_id = Column(Integer, ForeignKey("ecomapp_product.id"))
    size_id = Column(Integer, ForeignKey("ecomapp_size.id"))

    product = relationship("Product", foreign_keys=[product_id])
    size = relationship("Size", foreign_keys=[size_id])