Skip to content

How to include choices for ResourceRelatedField? #701

@arthur-s

Description

@arthur-s

I need to get choices for ResourceRelatedField, when I make OPTIONS request. How to do it?

# serializer:
self.fields['members'] = ResourceRelatedField(
    queryset=Profile.objects.filter(is_active=True),
    many=True
)

Current output:

                "members": {
                    "type": "Relationship",
                    "relationship_type": "ManyToMany",
                    "relationship_resource": "profiles",
                    "required": false,
                    "read_only": false,
                    "write_only": false,
                    "label": "Members",
                    "initial": "[]"
                },

If I remove this line, (It is what I want) I get desired output:

                "members": {
                    "type": "field",
                    "required": false,
                    "read_only": false,
                    "label": "Members",
                    "relationship_type": "ManyToMany",
                    "choices": [
                        {
                            "value": "{\"type\": \"profiles\", \"id\": \"1\"}",
                            "display_name": "Arthur"
                        },
                        {
                            "value": "{\"type\": \"profiles\", \"id\": \"2\"}",
                            "display_name": "Tom"
                        }
                    ]
                },

Can we remove not field_info.get('relationship_resource') and from choices condition, or how to generate output that I want (without modifying metadata.py)?

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