Last active
September 13, 2018 20:44
-
-
Save dbrgn/4e6fc1fe5922598592d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Moved to https://github.com/dbrgn/drf-dynamic-fields |
@lucasdavid The request is included by default in the context with ModelViewSet (look at the definition of get_serializer and get_serializer_context in generics.py). However, I had to add the following line:
if not self.context:
return
before
fields = self.context['request'].query_params.get('fields', None)
Without this, I would get an error when the server was starting up because there was no request object.
I just published this as a package on PyPI! https://github.com/dbrgn/drf-dynamic-fields
#Mark for my next google search# Another implementation: https://github.com/wimglenn/djangorestframework-queryfields
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@X17, any suggestions on how to use this without implementing the
get()
method? (I'm using a ModelViewSet)