我使用的烧瓶型号如下:
class NewsCategory(db.Model):
__tablename__ = 'news_category'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(64))
parent_id = db.Column(db.Integer, db.ForeignKey('news_category.id'))
children = db.relationship("NewsCategory")
我想从这个模型创建一个json对象,用于导航菜单。在
我希望递归地解析它并构建一个如下所示的分层JSON对象:
^{pr2}$
我使用一个名为Flask-Restless的库来查询数据库并返回json。它是用来和SQLAlchemy一起工作的。在
如果您不希望与这样的东西集成,那么您可以将SQLAlchemy模型子类化,并在其上运行tu json()方法。在
class NewsCategory(db.Model, JsonSerializer)
作者:Github Overholt project(Flask Security的作者)
相关问题 更多 >
编程相关推荐