假设我们有以下模型:
class Classroom(models.Model):
room_number = [...]
class Teacher(models.Model):
name = [...]
tenure = [...]
classroom = models.ForeignKey(Classroom)
假设不是根据 ManyRelatedPrimaryKeyField 函数得到这样的结果:
{
"room_number": "42",
"teachers": [
27,
24,
7
]
},
让它返回包含完整相关模型表示的内容,例如:
{
"room_number": "42",
"teachers": [
{
'id': 27,
'name': 'John',
'tenure': True
},
{
'id': 24,
'name': 'Sally',
'tenure': False
},
]
},
这可能吗?如果是这样,怎么做?这是一个坏主意吗?