-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter fields in embedded document #15
Comments
This is not currently supported. Why don't you simply create a serializer that only serializes some of the fields? |
We were hoping not to have to create one for every API's different use cases. We have a lot of listing api's that only need a subset of the model and their child documents fields so we feel the right approach is to have a general purpose interface that can filter on the request thus no need extra development and testing on each model. |
I see. This library is intentionally pretty simple, it just filters the fields of the top-level serializer. If you want to apply filters to nested serializers, that'll become a bit more complicated. If someone would provide a clean pull request with this feature and good test coverage, I wouldn't say no, but I don't have the capacity to add that feature right now. Maybe https://github.com/rsinger86/drf-flex-fields already does what you are looking for? |
I had looked at that one, but they seem to acknowledge the existence of the child documents and allow for expansion but I didn't notice a good way to restrict the output, and it would be more complex if we have multiple child document in a parent document. Thanks though, I appreciate you taking the time to review the request. |
Maybe you can create a feature request against drf-flex-fields. They seem to aim for more flexibilit than I do :) Otherwise, writing custom code for the specific filtering needs might be quite simple to implement. |
I think this is a feature request but is there a way to filter fields from embedded documents? Think of a base document (in mongodb) that looks like this in JSON:
and you only want to output: _id, name, embedded_doc.color
We are trying to avoid having to serialize the entire embedded doc since it could a be large memory footprint, especially when we are returning a list of the parent objects.
Thanks
The text was updated successfully, but these errors were encountered: