Changeset 8691
- Timestamp:
- 08/28/08 21:40:56 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/fields/__init__.py
r8684 r8691 363 363 _("This value must be either True or False.")) 364 364 365 def get_db_prep_lookup(self, lookup_type, value): 366 # Special-case handling for filters coming from a web request (e.g. the 367 # admin interface). Only works for scalar values (not lists). If you're 368 # passing in a list, you might as well make things the right type when 369 # constructing the list. 370 if value in ('1', '0'): 371 value = bool(int(value)) 372 return super(BooleanField, self).get_db_prep_lookup(lookup_type, value) 373 365 374 def get_db_prep_value(self, value): 366 375 if value is None: … … 694 703 _("This value must be either None, True or False.")) 695 704 705 def get_db_prep_lookup(self, lookup_type, value): 706 # Special-case handling for filters coming from a web request (e.g. the 707 # admin interface). Only works for scalar values (not lists). If you're 708 # passing in a list, you might as well make things the right type when 709 # constructing the list. 710 if value in ('1', '0'): 711 value = bool(int(value)) 712 return super(NullBooleanField, self).get_db_prep_lookup(lookup_type, value) 713 696 714 def get_db_prep_value(self, value): 697 715 if value is None: django/trunk/tests/regressiontests/model_fields/tests.py
r8616 r8691 46 46 datetime.time(1, 2, 3, 999999) 47 47 48 # Boolean and null boolean fields 49 >>> f = BooleanField() 50 >>> for val in (True, '1', 1): 51 ... f.get_db_prep_lookup('exact', val) 52 [True] 53 [True] 54 [True] 55 >>> for val in (False, '0', 0): 56 ... f.get_db_prep_lookup('exact', val) 57 [False] 58 [False] 59 [False] 60 61 >>> f = NullBooleanField() 62 >>> for val in (True, '1', 1): 63 ... f.get_db_prep_lookup('exact', val) 64 [True] 65 [True] 66 [True] 67 >>> for val in (False, '0', 0): 68 ... f.get_db_prep_lookup('exact', val) 69 [False] 70 [False] 71 [False] 72 >>> f.get_db_prep_lookup('exact', None) 73 [None] 48 74 49 75 """
