Skip to content

Add failing test case for #3788 #4284

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

Closed
wants to merge 3 commits into from
Closed

Add failing test case for #3788 #4284

wants to merge 3 commits into from

Conversation

flaiming
Copy link

Added failing test case for issue #3788. It tests that model's BooleanField default value (when True) is ignored on serializer.

@tomchristie
Copy link
Member

The key here is that HTML forms do not provide a value when a boolean checkbox is left empty.
We have to treat empty as false, and provided as true - the model default isn't relevant in the context of HTML forms as there's no 'empty' state.

If you switch from using QueryDict to using a regular dictionary (ie the behavior you'd get if providing JSON input) then you'd get the behavior you'd expect.

Closing this, as the behavior is as described in the documentation.

http://www.django-rest-framework.org/api-guide/fields/#booleanfield

When using HTML encoded form input be aware that omitting a value will always be treated as setting a field to False, even if it has a default=True option specified. This is because HTML checkbox inputs represent the unchecked state by omitting the value, so REST framework treats omission as if it is an empty checkbox input.

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

Successfully merging this pull request may close these issues.

2 participants