We are running DRF in combination with django filter to narrow down list view results.
As filters and filter options are increasing, we would like the frontend to display only the available (the select-able) filter choices.
- Simple example: There are a lot of products but none is green. The frontend should be able to disable/hide the checkbox for green by asking the DRF
- More complex example: There are a lot of products and all of the red ones are small. If the user selected the red filter (e.g. frontend calls
/products/?color=red
) there is no need to bother the user with filters for medium and large.
Currently, we are about to create a custom implementation based on DRF's options method: That is manually checking for available filter choices depending on the current query set and returning this info as the "actions":{ "GET": {...}}
dict
using e.g. custom metadata.
We could also augment the GET
response similar to the pagination API which already adds count
, next
and previous
to the answer.
However, this seems to be a rather common use case (e.g. in online shops) and thus I was wondering if there is a django-filter/DRF-onic way (a best practice) or even a library for that.