1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #8995: Enable arbitrary ordering of REST API results

This commit is contained in:
jeremystretch
2022-04-08 16:00:33 -04:00
parent 9b8de19fe6
commit 03535ce50b
4 changed files with 87 additions and 1 deletions

View File

@@ -106,3 +106,23 @@ expression: `n`. Here is an example of a lookup expression on a foreign key, it
```no-highlight
GET /api/ipam/vlans/?group_id__n=3203
```
## Ordering Objects
To order results by a particular field, include the `ordering` query parameter. For example, order the list of sites according to their facility values:
```no-highlight
GET /api/dcim/sites/?ordering=facility
```
To invert the ordering, prepend a hyphen to the field name:
```no-highlight
GET /api/dcim/sites/?ordering=-facility
```
Multiple fields can be specified by separating the field names with a comma. For example:
```no-highlight
GET /api/dcim/sites/?ordering=facility,-name
```