Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

ResourceRelatedField: Support resource_name in to_internal_value #302

Closed
@czosel

Description

@czosel

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions