yakczh
V2EX  ›  问与答

SQLAlchemy 从数据库读出纪录怎么输出 json

  •  
  •   yakczh · Dec 30, 2014 · 4344 views
    This topic created in 4166 days ago, the information mentioned may be changed or developed.
    照http://simplectic.com/blog/2014/flask-todomvc-sqlalchemy/ 上面的例子 要对每个表字段挨个配置一遍
    def to_json(self):
    return {
    "id": self.id,
    "title": self.title,
    "order": self.order,
    "completed": self.completed}

    def from_json(self, source):
    if 'title' in source:
    self.title = source['title']
    if 'order' in source:
    self.order = source['order']
    if 'completed' in source:
    self.completed = source['completed']
    除了这种方式,还有别的简单一点的办法吗?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1019 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 18:45 · PVG 02:45 · LAX 11:45 · JFK 14:45
    ♥ Do have faith in what you're doing.