【发布时间】:2014-11-06 23:07:34
【问题描述】:
在我的模型中,目前我有 3 个类:
- 任务:任务的基本属性
- GoToAndAnswer:有点像任务类型,它扩展了 Quest
- SeekAndAnswer:同上,扩展Quest
我正在使用 Django 构建 API,因此在我的视图中,我想以 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
但它没有帮助......
提前致谢
【问题讨论】:
标签: django python-2.7