Serialize the options from ModelMultipleChoiceFilter for use with DRF #1690
-
Heya, first of all, thank you for your work on this package. It really helped me a lot. In the past, I built a library like page with Now I want to create a web API for that HTML view and I am looking for a possibility to serialize what would be rendered into the forms to include it into the API's response so that I can use it to populate the filter forms of my application. I've been going through "Integration with DRF" and the other discussion to no avail. I hope I haven't missed anything. I see how you could implement the filtering client-side only, but that would certain filter views or server-side pagination rather hard. I guess you could also run separate queries but that seems unnecessary given that the filtered view has all the data already. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @alexanderjulmer. So... DRF with use django-filter via To pass the choices to the client-side you'd need to serialise them yourself...
... and then you send that to the frontend to build the form UI. Make sense? |
Beta Was this translation helpful? Give feedback.
Hi @alexanderjulmer.
So... DRF with use django-filter via
filter_backends
to actually filter the request, and then the Browsable API will render the form in the HTML — but all of that is server-side.To pass the choices to the client-side you'd need to serialise them yourself...
... and then you send that to the frontend to build the form UI.
Make sense?