-
Notifications
You must be signed in to change notification settings - Fork 300
Description
I'm trying to modify the type of a ResourceRelatedField: Instead of the model name, i'd like to serve another name.
For GET requests, that works nicely because to_representation considers resource_name on the serializer (if the field is part of included_serializers).
However, POSTing a new resource under the different resource_name does not work, because to_internal_value considers only the model for expected_relation_type.
Suggestion: Allow passing resource_name to ResourceRelatedField. If specified, it
- is used in
to_internal_valueto map to the actual resource name (which is read from the queryset) - should take priority over
resource_nameon the serializer into_representation
What do you think? Is there an easier approach to this? I'd be happy to provide a PR if you think this is the way to go.
PS: In case you wonder, our use case for this: We need two different endpoints with different permissions and serializers for the same underlying Django model. (The "owner" of the model sees more than anyone else.)