I'm calling the following serializer -
class ResourceSerializer(serializers.ModelSerializer):
class Meta:
model = Resmst
resource_name = 'resmst'
fields = ('resmst_id', 'resmst_name', 'resmst_desc', 'resmst_limit', 'resmst_inuse', 'resmst_active', 'resmst_lstchgtm',
'resmst_prntid', 'resmst_owner', 'resmst_public', 'resmst_locked', 'resmst_offline')
read_only_fields = ('resmst_id',)
resmst_owner is a FK relation to another table. What I want to do is have the serializer display the information from a column where that FK relates.
This is the current json -
[
{
"resmst_id": 204,
"resmst_name": "GAWK",
"resmst_desc": null,
"resmst_limit": 1,
"resmst_inuse": 0,
"resmst_active": "Y",
"resmst_lstchgtm": "2014-08-20T11:15:18",
"resmst_prntid": null,
"resmst_owner": 822,
"resmst_public": "Y",
"resmst_locked": null,
"resmst_offline": 0
}
]
And this is how I want it to look -
[
{
"resmst_id": 204,
"resmst_name": "GAWK",
"resmst_desc": null,
"resmst_limit": 1,
"resmst_inuse": 0,
"resmst_active": "Y",
"resmst_lstchgtm": "2014-08-20T11:15:18",
"resmst_prntid": null,
"owner_name": "John Smith",
"resmst_public": "Y",
"resmst_locked": null,
"resmst_offline": 0
}
]
Or am I stuck with having to do it this way -
[
{
"resmst_id": 204,
"resmst_name": "GAWK",
"resmst_desc": null,
"resmst_limit": 1,
"resmst_inuse": 0,
"resmst_active": "Y",
"resmst_lstchgtm": "2014-08-20T11:15:18",
"resmst_prntid": null,
"resmst_owner": {
"owner_name": "John Smith"
},
"resmst_public": "Y",
"resmst_locked": null,
"resmst_offline": 0
}
]