Allows clients to control which fields will be sent in the API response, now in a multidimensional nest of levels! Fields are specified in the query and separated by points determining a given depth with no limit, e.g.
# You want a list of users but you're only interested in the fields "email" and "username":
GET /users/?fields=email,username
[
{
"email": "bruno@gmail.com",
"username": "bruno"
},
{
"email": "endzel@gmail.com",
"username": "endzel"
}
]
# You want to see every field except "id" for the specific user endzel:
GET /users/2/?fields!=id
{
"username": "endzel",
"email": "endzel@gmail.com",
"drinks": "tea",
"location": {
"id": 1,
"country_name": "Spain",
"city": "Málaga"
}
}
# And, you just want to filter "username" and "city" for the "location" attribute within the user endzel:
GET /users/2/?fields=username,location.city
{
"username": "endzel",
"location": {
"city": "Málaga"
}
}
Supported Django versions: 4.2 - 6.0+. Check the CI matrix for details.
Documentation is hosted on Read The Docs.
Want to contribute to the project? This is how to run the test suite:
# Get the repo (hopefully with a ⭐)
git clone https://github.com/Endzel/drf-nestedqueryfields.git
# Create and activate your virtual environment
python -m venv .venv
source .venv/bin/activate
# Install the app
pip install --editable ".[dev]"
git checkout -b myfeature
# Do your thing, and then fire the tests with
python -m pytestMany thanks to Wim Glenn, author of the original DRF QueryFields repository from which this one was forked, that inspired me to add my two cents!