Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@choices representation of RelatedField #3365

Closed
LennyLip opened this issue Sep 3, 2015 · 1 comment
Closed

@choices representation of RelatedField #3365

LennyLip opened this issue Sep 3, 2015 · 1 comment
Labels
Milestone

Comments

@LennyLip
Copy link

LennyLip commented Sep 3, 2015

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.

@tomchristie tomchristie added this to the 3.4.4 Release milestone Aug 10, 2016
@tomchristie
Copy link
Member

tomchristie commented Aug 10, 2016

Yup, that seems like a valid request to me.
We no longer display relational choices in OPTIONS by default, but the underlying change here is still reasonable & correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants