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, POST
ing 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_value
to map to the actual resource name (which is read from the queryset) - should take priority over
resource_name
on 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.)