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

ChoiceField.valid_value() Fails due to Label when filter with query params #62

Closed
legshort opened this issue Jul 20, 2016 · 4 comments
Closed

Comments

@legshort
Copy link

legshort commented Jul 20, 2016

I would like to report a weird action when I try to use filtering with DRF 3.4, django-filter 0.13 and django-enumfields 0.8.1, drf-enum-field 0.9.1
I made a request with url http://url/api/MyModels?test_type=a and the response said "['Select a valid choice. A is not one of the available choices.']".
It turns out that ChoiceField.valid_value() returns False because k, v in choices are both label instead of name and value so it keeps failing.
They should be name and value and tries to compare with query param which is 'a'.
This is my sample code

class TestType(Enum) 
    A = 'a'

    class Labels:
        A = 'a-label'

class MyModel(Model):
    test_type = EnumField(TestType, max_length=MAX_TEST_TYPE_LENGTH)

I think EnumField should override valid_value() and makes sure overridden method called instead of ChoiceField.

@akx
Copy link
Contributor

akx commented Jul 20, 2016

Django-Enumfields 0.1.0? That's a positively ancient version.

Can you try upgrading to a newer version?

Also, for interoperability with DRF, maybe see this issue comment :)

@legshort
Copy link
Author

my bad, I changed the version to django-enumfields 0.8.1 and drf-enum-field 0.9.1.
Yeah sure, let me try that, thanks.

@akx
Copy link
Contributor

akx commented Jul 29, 2016

@legshort Any luck?

@akx
Copy link
Contributor

akx commented Jan 16, 2020

Closing as ancient.

@akx akx closed this as completed Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants