외래 키에서 필드를 추가Djangorestframework Modelresource 지금이 JSON 데이터를 반환 내가 장고 - 나머지 프레임 워크의 API를
[
{
"id": 1,
"foreignobject": {
"id": 3
},
"otherfields": "somevalue"
}
]
그러나 내가 그것을 이런 식으로 뭔가를 반환하려면을 (그 ID로 foreigneky을 평평 전용) :
[
{
"id": 1,
"foreignobject_id":3,
"otherfields": "somevalue"
}
]
) 지금은 (단순화, 모델 자원에 이렇게 :
class ForeignKeyInDataResource(ModelResource):
model = TheOtherModel
fields = ('id',)
class SomeModelResource(ModelResource):
model = SomeModel
fields = ('id',('foreignobject','ForeignKeyInDataResource'),'otherfields',)
가 이미 같은 시도 :
:class SomeModelResource(ModelResource):
model = SomeModel
fields = ('id','foreignobject__id','otherfields',)
을하지만 그 전체 이야기에 대한
를 작동하지 않았다, 뷰는 데이터를 반환이 방법 목록은 SomeModel으로 쿼리의 결과
data = Serializer(depth=2).serialize(list)
return Response(status.HTTP_200_OK, data)
덕분에이 제안에 대해, 내가 명심하겠습니다, 업데이트 지금 옵션이 아닙니다. –
또 다른 질문에서 보았을 때 당신은 대답했습니다 ... 이주 작업. 나머지 프레임 워크의 최신 버전에 대한 경로에서 완료된 아주 멋진 작업! –