mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Added info about API _choices endpoints
This commit is contained in:
parent
17a45109f4
commit
6052405eb7
@ -88,10 +88,10 @@ The base serializer is used to represent the default view of a model. This inclu
|
|||||||
"vid": 101,
|
"vid": 101,
|
||||||
"name": "Users-Floor1",
|
"name": "Users-Floor1",
|
||||||
"tenant": null,
|
"tenant": null,
|
||||||
"status": [
|
"status": {
|
||||||
1,
|
"value": 1,
|
||||||
"Active"
|
"label": "Active"
|
||||||
],
|
},
|
||||||
"role": {
|
"role": {
|
||||||
"id": 9,
|
"id": 9,
|
||||||
"url": "http://localhost:8000/api/ipam/roles/9/",
|
"url": "http://localhost:8000/api/ipam/roles/9/",
|
||||||
@ -122,6 +122,37 @@ When a base serializer includes one or more nested serializers, the hierarchical
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Static Choice Fields
|
||||||
|
|
||||||
|
Some model fields, such as the `status` field in the above example, utilize static integers corresponding to static choices. The available choices can be retrieved from the read-only `_choices` endpoint within each app. A specific `model:field` tuple may optionally be specified in the URL.
|
||||||
|
|
||||||
|
Each choice includes a human-friendly label and its corresponding numeric value. For example, `GET /api/ipam/_choices/prefix:status/` will return:
|
||||||
|
|
||||||
|
```
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"value": 0,
|
||||||
|
"label": "Container"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 1,
|
||||||
|
"label": "Active"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 2,
|
||||||
|
"label": "Reserved"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": 3,
|
||||||
|
"label": "Deprecated"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Thus, to set a prefix's status to "Reserved," it would be assigned the integer `2`.
|
||||||
|
|
||||||
|
A request for `GET /api/ipam/_choices/` will return choices for _all_ fields belonging to models within the IPAM app.
|
||||||
|
|
||||||
# Pagination
|
# Pagination
|
||||||
|
|
||||||
API responses which contain a list of objects (for example, a request to `/api/dcim/devices/`) will be paginated to avoid unnecessary overhead. The root JSON object will contain the following attributes:
|
API responses which contain a list of objects (for example, a request to `/api/dcim/devices/`) will be paginated to avoid unnecessary overhead. The root JSON object will contain the following attributes:
|
||||||
|
Loading…
Reference in New Issue
Block a user