Flask sqlalchemy将json值插入表中而不读取每个colunm

时间:2016-09-07 06:58:33

标签: python sqlalchemy

模型

class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, Sequence("user_id_sq"), primary_key=True)
    name = Column(String(20))
    fullname = Column(String(50))
    password = Column(String(20))

    def __init__(self, id, name, fullname, password):
        """"""
        self.id = id
        self.name = name
        self.fullname = fullname
        self.password = password

    def __repr__(self):
       return "<User(name='%s', fullname='%s', password='%s')>" % (
                             self.name, self.fullname, self.password)

数据

data = {"id":1,"name":"Eswar","fullname":"S","password":"123456aA"}

user_data = User(data["id"],
                 data["name"],
                 data["fullname"],
                 data["password"])

不是通过user_data的键读取每个值,而是我们可以将数据插入到表中,并将各自的值插入到列中。

0 个答案:

没有答案