Ticket #7190: django-boolean_mysql_r12847.patch
File django-boolean_mysql_r12847.patch, 4.1 KB (added by , 15 years ago) |
---|
-
django/db/backends/mysql/base.py
125 125 related_fields_match_type = True 126 126 127 127 class DatabaseOperations(BaseDatabaseOperations): 128 compiler_module = "django.db.backends.mysql.compiler" 129 128 130 def date_extract_sql(self, lookup_type, field_name): 129 131 # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html 130 132 if lookup_type == 'week_day': … … 224 226 second = '%s-12-31 23:59:59.99' 225 227 return [first % value, second % value] 226 228 229 def convert_values(self, value, field): 230 if (field.get_internal_type() in ("BooleanField", "NullBooleanField") and 231 value in (0, 1)): 232 return bool(value) 233 return value 234 227 235 class DatabaseWrapper(BaseDatabaseWrapper): 228 236 229 237 operators = { -
django/db/backends/mysql/compiler.py
1 from django.db.models.sql import compiler 2 3 class SQLCompiler(compiler.SQLCompiler): 4 def resolve_columns(self, row, fields=()): 5 values = [] 6 for value, field in map(None, row, fields): 7 values.append(self.query.convert_values(value, field, connection=self.connection)) 8 return tuple(values) 9 10 11 class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler): 12 pass 13 14 class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler): 15 pass 16 17 class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler): 18 pass 19 20 class SQLAggregateCompiler(compiler.SQLAggregateCompiler, SQLCompiler): 21 pass 22 23 class SQLDateCompiler(compiler.SQLDateCompiler, SQLCompiler): 24 pass -
tests/regressiontests/model_fields/tests.py
6 6 from django.db import models 7 7 from django.core.exceptions import ValidationError 8 8 9 from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel 9 from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel 10 10 11 11 try: 12 12 from decimal import Decimal … … 161 161 162 162 f = models.BooleanField(choices=choices, default=1, null=False) 163 163 self.assertEqual(f.formfield().choices, choices) 164 165 def test_return_type(self): 166 b = BooleanModel() 167 b.bfield = True 168 b.save() 169 b2 = BooleanModel.objects.get(pk=b.pk) 170 self.assertTrue(isinstance(b2.bfield, bool)) 171 self.assertEqual(b2.bfield, True) 164 172 173 b3 = BooleanModel() 174 b3.bfield = False 175 b3.save() 176 b4 = BooleanModel.objects.get(pk=b3.pk) 177 self.assertTrue(isinstance(b4.bfield, bool)) 178 self.assertEqual(b4.bfield, False) 179 180 b = NullBooleanModel() 181 b.nbfield = True 182 b.save() 183 b2 = NullBooleanModel.objects.get(pk=b.pk) 184 self.assertTrue(isinstance(b2.nbfield, bool)) 185 self.assertEqual(b2.nbfield, True) 186 187 b3 = NullBooleanModel() 188 b3.nbfield = False 189 b3.save() 190 b4 = NullBooleanModel.objects.get(pk=b3.pk) 191 self.assertTrue(isinstance(b4.nbfield, bool)) 192 self.assertEqual(b4.nbfield, False) 193 165 194 class ChoicesTests(django.test.TestCase): 166 195 def test_choices_and_field_display(self): 167 196 """ -
tests/regressiontests/model_fields/models.py
67 67 class NullBooleanModel(models.Model): 68 68 nbfield = models.NullBooleanField() 69 69 70 class BooleanModel(models.Model): 71 bfield = models.BooleanField() 70 72 71 73 ############################################################################### 72 74 # ImageField