Skip to content

@choices representation of RelatedField #3365

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy