V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yakczh
V2EX  ›  问与答

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

  •  
  •   yakczh · 2014-12-30 22:05:43 +08:00 · 3982 次点击
    这是一个创建于 3424 天前的主题,其中的信息可能已经有所发展或是发生改变。
    照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']
    除了这种方式,还有别的简单一点的办法吗?
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1074 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 19:28 · PVG 03:28 · LAX 12:28 · JFK 15:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.