Python peewee:classname\u设置为json数组

Python peewee:classname\u设置为json数组,python,peewee,Python,Peewee,我正在尝试使用Python peewee获取以下json {'id':1,'name':'John','tweet_set':[{'id':1,'message':'hello'}, {'id':2,'message':'world'}]} 但我能想到的是: {'id':1,'message':'hello','user':{'id':1,'name':'John'} {'id':2,'message':'world','user':{'id':1,'name':'John'} 这是我的密码

我正在尝试使用Python peewee获取以下json

{'id':1,'name':'John','tweet_set':[{'id':1,'message':'hello'},
{'id':2,'message':'world'}]}
但我能想到的是:

{'id':1,'message':'hello','user':{'id':1,'name':'John'}
{'id':2,'message':'world','user':{'id':1,'name':'John'}
这是我的密码。我可以在哪里/做什么更改以获取一系列tweet

来自peewee导入的
*
从playhouse.shortcuts将模型_导入到_dict,dict_导入到_model
db=SqliteDatabase('/tmp/a.db')
类BaseModel(模型):
类元:
数据库=db
类用户(基本模型):
id=PrimaryKeyField()
name=CharField()
类Tweet(基本模型):
id=PrimaryKeyField()
message=CharField()
user=ForeignKeyField(用户)
db.connect()
db.create_表([User,Tweet])
db.close()
user\u id=user.create(name=“John”)
create(message=“hello”,user=user\u id)
create(message=“world”,user=user\u id)
u=User.get(User.name=='John')
对于u.tweet_集合中的t:
印刷品(型号(t))
试试:


请参阅包含示例的文档:

can u post数据在db中的外观。感谢you@zenwraight你是什么意思?这一切都在代码中;我有两个表
User
Tweet
。表
User
有一行
name=“John”
,表
Tweet
有两行,
message=“hello”
message=“world”
print(model_to_dict(u, backrefs=True))