第 4 章 API 中的排序
为了让您易于使用,我们在整个指南中使用以下 URL:
https://<controller server name>/api/v2/groups/
https://<controller server name>/api/v2/groups/
流程
要指定 {{ model_verbose_name_plural }} 以特定顺序返回,请使用
GET请求上的order_by查询字符串参数:https://<controller server name>/api/v2/model_verbose_name_plural?order_by={{ order_field }}https://<controller server name>/api/v2/model_verbose_name_plural?order_by={{ order_field }}Copy to Clipboard Copied! Toggle word wrap Toggle overflow 为字段名称加上短划线(
-)前缀,以反向排序:https://<controller server name>/api/v2/model_verbose_name_plural?order_by=-{{ order_field }}https://<controller server name>/api/v2/model_verbose_name_plural?order_by=-{{ order_field }}Copy to Clipboard Copied! Toggle word wrap Toggle overflow 您可以使用逗号分隔字段名称(、
、)来指定排序字段:https://<controller server name>/api/v2/model_verbose_name_plural?order_by={{ order_field }},some_other_fieldhttps://<controller server name>/api/v2/model_verbose_name_plural?order_by={{ order_field }},some_other_fieldCopy to Clipboard Copied! Toggle word wrap Toggle overflow