Skip to content

Commit

Permalink
Only HTML forms should have implicit default False for boolean fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Aug 19, 2013
1 parent 34d6511 commit 28ff6fb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.core.exceptions import ValidationError
from django.conf import settings
from django.db.models.fields import BLANK_CHOICE_DASH
from django.http import QueryDict
from django.forms import widgets
from django.utils.encoding import is_protected_type
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -399,10 +400,15 @@ class BooleanField(WritableField):
}
empty = False

# Note: we set default to `False` in order to fill in missing value not
# supplied by html form. TODO: Fix so that only html form input gets
# this behavior.
default = False
def field_from_native(self, data, files, field_name, into):
# HTML checkboxes do not explicitly represent unchecked as `False`
# we deal with that here...
if isinstance(data, QueryDict):
self.default = False

return super(BooleanField, self).field_from_native(
data, files, field_name, into
)

def from_native(self, value):
if value in ('true', 't', 'True', '1'):
Expand Down

0 comments on commit 28ff6fb

Please sign in to comment.