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
Queryset based on request #2292
Comments
Conversation on this here: #1985. |
Overriding def __init__(self, *args, **kwargs):
user = kwargs['context']['request'].user
if not user.is_staff:
book_f = self.fields['book']
book_f.queryset = book_f.queryset.filter(organisation=user.organisation)
super(ExampleSerializer, self).__init__(*args, **kwargs) |
@tomchristie is there any better approach for this yet? I am running into a bunch of issues caused largely by requiring the request in serializers – e.g. django-rest-swagger wants to access the fields for introspection and doesn't pass a context along |
In which case I'd suggest overriding |
I am just upgrading to DRF 3.0, and I am pretty much there.
One thing for the upgrade docs / helping me... how do I contextualise the queryset now required for related fields to the request?
At ViewSet level, for the results, remains easy:
But when customising the choices for a relation in a serializer:
The text was updated successfully, but these errors were encountered: