You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_value to map to the actual resource name (which is read from the queryset)
should take priority over resource_name on the serializer in to_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.)
The text was updated successfully, but these errors were encountered:
After giving this some more thought, i noticed that it would make much more sense if to_internal_value works the same way as to_representation: By checking Meta.resource_name on the corresponding serializer. So thats how i implemented it in #306.
I'm trying to modify the
type
of aResourceRelatedField
: Instead of the model name, i'd like to serve another name.For
GET
requests, that works nicely becauseto_representation
considersresource_name
on the serializer (if the field is part ofincluded_serializers
).However,
POST
ing a new resource under the differentresource_name
does not work, becauseto_internal_value
considers only the model forexpected_relation_type
.Suggestion: Allow passing
resource_name
toResourceRelatedField
. If specified, itto_internal_value
to map to the actual resource name (which is read from the queryset)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.)
The text was updated successfully, but these errors were encountered: