Movatterモバイル変換


[0]ホーム

URL:


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 inGeneral
Discussion options

returnself.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 ofto_internal_value.

Vanilla DRF provides aqueryset 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 overwritevalidate though.

But is not overwriting thequeryset inRelationshipView what you are looking for?

You must be logged in to vote
2 replies
@SafaAlfulaij
Comment options

Alright, for fetching data,queryset should be enough.
But posting/patching/removing uses the serializers's queryset.
Also, sinceRelationshipView 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 overwritingvalidate 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).

@sliverc
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 freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
2 participants
@SafaAlfulaij@sliverc
Converted from issue

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


[8]ページ先頭

©2009-2025 Movatter.jp