我有以下课程:
class Identity(Base):
"Identity model."
__tablename__ = 'identity'
id = Column('ID_IDENTITY', Integer, Sequence('identity_seq'), primary_key=True, nullable=False)
uuid = Column('DS_UUID', String(32), ForeignKey('customer.NX_UUID'), nullable=False)
type = Column('DS_TYPE', String(255), nullable=False)
value = Column('DS_VALUE', String(255), nullable=False)
和
class Customer(Base):
"Customer model."
__tablename__ = 'customer'
uuid = Column('NX_UUID', String(32), primary_key=True, nullable=False)
name = Column('DS_NICK_NAME', String(255), nullable=False)
identities = relationship(Identity, backref=backref('custome', cascade='all', uselist=True), lazy='dynamic')
我想发布一个新客户传递一个契约列表,我试图通过跟随json这样做:
{"name":"Teste", uuid: "12121212121","identities":[{"type":"cpf","value":"05882110955"}, {"CNPJ":"0123456656"}, {"RG":"AAA3243"}]}
但是我收到了错误:
unhashable type: 'dict'
要做到这一点的任何想法吗?
TKS
答案 0 :(得分:0)
您需要创建标识SQLAlchemy模型对象,如下所示:
cust = Customer(name="Test", uuid="12121212121")
id1 = Identity(type="cpf", value="05882110955", uuid="asdasda")
id2 = Identity(type="CNPJ", value="0123456656", uuid="sdzxc3")
cust.identites = [id1, id2]
db_session.add(cust)
db_session.commit()