Skip to content

@choices representation of RelatedField #3365

Closed
@LennyLip

Description

@LennyLip

can we change
https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/relations.py#L154

from

    return OrderedDict([
        (
            six.text_type(self.to_representation(item)),
            self.display_value(item)
        )
        for item in queryset

to

    return OrderedDict([
        (
            force_text(self.to_representation(item), strings_only=True),
            self.display_value(item)
        )
        for item in queryset

????

When i make OPTION request, i've got metada for related field choices of action:
1st case:

{display_name: "Acura", value: "184"} (this is wrong)

2nd case:

{display_name: "Acura", value: 184} (it's ok)

Here we got field.choices:

https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/metadata.py#L142

        field_info['choices'] = [
            {
                'value': choice_value,
                'display_name': force_text(choice_name, strings_only=True)
            }
            for choice_value, choice_name in field.choices.items()

value is always string now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions