Composing requests that filter and order results
We will compose and send an HTTP request to retrieve all the drones whose related drone category ID is equal to 1
and whose value for the has_it_competed
field is equal to False
. The results must be sorted by name
in descending order, and therefore, we specify -name
as the value for the ordering
query parameter.
Note
The hyphen (-
) before the field name indicates that the ordering feature must use descending order instead of the default ascending order.
Make sure you replace 1
with the pk
value of the previously retrieved drone category named Quadcopter
. The has_it_competed
field is a bool
field, and therefore, we have to use Python valid bool values (True
and False
) when specifying the desired values for the bool field in the filter:
http ":8000/drones/?
drone_category=1&has_it_competed=False&ordering=-name"
The following is the equivalent curl
command:
curl -iX GET "localhost:8000/drones/?
drone_category=1&has_it_competed=False...