From f3ced9ab8301a0a2f261c963fa8d225143fc2aa2 Mon Sep 17 00:00:00 2001 From: Frank Clements Date: Thu, 4 Apr 2024 11:41:27 -0400 Subject: [PATCH] add example showing how to order results. This addresses issue 15622 by building off filtering example to show how to order results on a named field. --- docs/integrations/rest-api.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/integrations/rest-api.md b/docs/integrations/rest-api.md index 437f652b7..a87ba7da3 100644 --- a/docs/integrations/rest-api.md +++ b/docs/integrations/rest-api.md @@ -85,13 +85,19 @@ Each model generally has two views associated with it: a list view and a detail * `/api/dcim/devices/` - List existing devices or create a new device * `/api/dcim/devices/123/` - Retrieve, update, or delete the device with ID 123 -Lists of objects can be filtered using a set of query parameters. For example, to find all interfaces belonging to the device with ID 123: +Lists of objects can be filtered or ordered using a set of query parameters. For example, to find all interfaces belonging to the device with ID 123: ``` GET /api/dcim/interfaces/?device_id=123 ``` -See the [filtering documentation](../reference/filtering.md) for more details. +An optional `ordering` parameter can be used to define how to sort the results. Building off the previous example, to sort all the interfaces in reverse order of creation (newest to oldest) for a device with ID 123: + +``` +GET /api/dcim/devices/?device_id=123&ordering=-creation +``` + +See the [filtering documentation](../reference/filtering.md) for more details on topics related to filtering, ordering and lookup expressions. ## Serialization