summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2010-02-24 17:36:18 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2010-02-24 17:36:18 +0000
commit16fe73d918c8a35f7122aed858312bd3163ac454 (patch)
tree06c8c09da94ae39e91735feb581139a2c242a138 /django
parent9f4bf525f887db32b7260909a0140d68910aa042 (diff)
Fixed #7190. Boolean fields now return bool values instead of 1 or 0. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12578 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/__init__.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 05f16db9fe..02c69c272e 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -524,9 +524,14 @@ class BooleanField(Field):
return "BooleanField"
def to_python(self, value):
- if value in (True, False): return value
- if value in ('t', 'True', '1'): return True
- if value in ('f', 'False', '0'): return False
+ if value in (True, False):
+ # if value is 1 or 0 than it's equal to True or False, but we want
+ # to return a true bool for semantic reasons.
+ return bool(value)
+ if value in ('t', 'True', '1'):
+ return True
+ if value in ('f', 'False', '0'):
+ return False
raise exceptions.ValidationError(self.error_messages['invalid'])
def get_prep_lookup(self, lookup_type, value):
@@ -934,10 +939,16 @@ class NullBooleanField(Field):
return "NullBooleanField"
def to_python(self, value):
- if value in (None, True, False): return value
- if value in ('None',): return None
- if value in ('t', 'True', '1'): return True
- if value in ('f', 'False', '0'): return False
+ if value is None:
+ return None
+ if value in (True, False):
+ return bool(value)
+ if value in ('None',):
+ return None
+ if value in ('t', 'True', '1'):
+ return True
+ if value in ('f', 'False', '0'):
+ return False
raise exceptions.ValidationError(self.error_messages['invalid'])
def get_prep_lookup(self, lookup_type, value):