0
在我的模型我有,就目前而言,3类:如何查询对象及其子对象为JSON?
- 任务:追求
- GoToAndAnswer的基本属性:还挺类型的追求的,它扩展了任务
- SeekAndAnswer:同上,延伸任务
我正在使用Django来构建一个API,因此在我的视图中我想打印关于这些Quests的信息以JSON格式。问题是我不知道如何正确序列化对象(我真的在新的Django和Python):
# Only get the attributes of the class Quest, obviously
serializers.serialize("json", Quest.objects.all())
# Only get the atributes of the GoToAndAnswer, nothing about the Quest attributes
serializers.serialize("json", GoToAndAnswer.objects.all())
因此,这是实现这一目标的最佳方式是什么?
我看到的帖子是这样的:JSON Serialization of a Django inherited model
但它并没有帮助...提前
感谢