-
Notifications
You must be signed in to change notification settings - Fork 300
RelationshipView doesn't provide a way to modify relations queryset for fetching and validation #936
-
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
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
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).
Beta Was this translation helpful? Give feedback.
All reactions
-
I am a bit confused by your explanation. Could you post a code snippet how you would picture an improvement?
Beta Was this translation helpful? Give feedback.