-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Choice values are always represented as strings. #4111
Comments
Black list string |
May I have steps to reproduce this? I am interested to look into it. I tried to reproduce but I couldn't. |
Open On Jun 12, 2016 5:41 PM, "Ansuman Bebarta" notifications@github.com wrote:
|
Here is an example:
If you add the viewset to your url router, and request OPTIONS, the choices for the foreign key (ExampleTypeModel) will all be strings. I believe the problem is here, it looks like its always forcing it to a string value? |
Hi, Thank you for the steps you have provided. I am getting following while requesting OPTIONS. But I am not getting choices for the foreign key. {
"name": "Example Model List",
"description": "",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"id": {
"type": "integer",
"required": false,
"read_only": true,
"label": "Id"
},
"name": {
"type": "string",
"required": true,
"read_only": false,
"label": "Name",
"max_length": 100
},
"example_type": {
"type": "field",
"required": true,
"read_only": false,
"label": "Example type"
}
}
}
} I have forked the lastest django-rest-framework repo so that I can create PR. Now after a bit of searching I found following: |
Closed, both via #4021 (Don't show in OPTIONS - thanks @ansumanbebarta!) and via #4379 (.choices property of RelatedField should preserve non-string values.) |
If you call OPTIONS on a model that has fields with choices, the displayed choices are always strings eg:
Currently for
RelatedField
, when you request thechoices
property, all values are converted to strings, but this probably doesn't make sense on things such asPrimaryKeyRelatedField
, or other field values which are integers or booleans.The text was updated successfully, but these errors were encountered: