Synthetic Fields
Each resource, whether it be in a List view or a Detail view, has a default serialization structure.
Let's look at a Location in List view, for example:
{
"id": 1701,
"api_url": "https://deploy.c1engineering.com/api/projects/locations/1701/",
"gui_url": "https://deploy.c1engineering.com/projects/myproject/locations/1701/",
"added_at": "2063-04-05T11:00:00.000000-08:00",
"modified_at": "2063-04-05T11:00:00.000000-08:00",
"created_at": "2063-04-05T11:00:00.000000-08:00",
"name": "Zefram's House",
"notes": "Warp or bust",
"site": 1,
"group": 1
},
In this default serialization, we see various fields like name, notes, site, and group. The Site and Location Group relationships use the default serialized field id.
This is fine, but what if we want to see the Site's name in this view? We can add synthetic fields to the default serialization using the add_fields query parameter
List Locations, and add the Site's name field to the serialization
The results from this query will look something like this:
{
"id": 1701,
"api_url": "https://deploy.c1engineering.com/api/projects/locations/1701/",
"gui_url": "https://deploy.c1engineering.com/projects/myproject/locations/1701/",
"added_at": "2063-04-05T11:00:00.000000-08:00",
"modified_at": "2063-04-05T11:00:00.000000-08:00",
"created_at": "2063-04-05T11:00:00.000000-08:00",
"name": "Zefram's House",
"notes": "Warp or bust",
"site": 1,
"group": 1,
"site__name": "Bozeman, MT"
}
And of course, you can span relationships when adding synthetic fields, like adding the Project's name to the serialization:
List Locations, and add the Site's and Project's name fields to the serialization
/api/projects/locations/?add_fields=site__name,site__project__name
As seen above, you can add multiple synthetic fields by separating them with commas.