Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RelationshipView doesn't provide a way to modify relations queryset for fetching and validation #936

SafaAlfulaij started this conversation in General
Discussion options

return self.model_class.objects.get(pk=pk)

There is no way to change the queryset used for fetching the related input field but to subclass the class and replace all of to_internal_value.

Vanilla DRF provides a queryset parameter for related fields to do the mentioned. Checkout:
https://github.com/encode/django-rest-framework/blob/master/rest_framework/relations.py#L243-L260

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

ResourceIdentifierObjectSerializer is a serializer class and not a relation and that is why there is no queryset for validation. On a serializer you can always overwrite validate though.

But is not overwriting the queryset in RelationshipView what you are looking for?

You must be logged in to vote
2 replies
Comment options

Alright, for fetching data, queryset should be enough.
But posting/patching/removing uses the serializers's queryset.
Also, since RelationshipView supports multiple creation/removing, we should validate all the data in one go (normally, DRF validates each serializer independently, resulting to o(n) queries).

Perhaps overwriting validate will work for this type of serializers given the above differences. But it is better if it's in the library rather than having it in each app's source (mostly the exact same code).

Comment options

I am a bit confused by your explanation. Could you post a code snippet how you would picture an improvement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Converted from issue

This discussion was converted from issue #922 on April 30, 2021 19:10.

AltStyle によって変換されたページ (->オリジナル) /