Changeset 7743
- Timestamp:
- 06/25/08 22:11:32 (3 months ago)
- Files:
-
- django/trunk/django/db/backends/oracle/creation.py (modified) (2 diffs)
- django/trunk/django/db/models/fields/__init__.py (modified) (2 diffs)
- django/trunk/django/utils/datastructures.py (modified) (1 diff)
- django/trunk/tests/regressiontests/queries/models.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/backends/oracle/creation.py
r6378 r7743 6 6 # be interpolated against the values of Field.__dict__ before being output. 7 7 # If a column type is set to None, it won't be included in the output. 8 # 9 # Any format strings starting with "qn_" are quoted before being used in the 10 # output (the "qn_" prefix is stripped before the lookup is performed. 11 8 12 DATA_TYPES = { 9 13 'AutoField': 'NUMBER(11)', 10 'BooleanField': 'NUMBER(1) CHECK (%( column)s IN (0,1))',14 'BooleanField': 'NUMBER(1) CHECK (%(qn_column)s IN (0,1))', 11 15 'CharField': 'NVARCHAR2(%(max_length)s)', 12 16 'CommaSeparatedIntegerField': 'VARCHAR2(%(max_length)s)', … … 20 24 'IntegerField': 'NUMBER(11)', 21 25 'IPAddressField': 'VARCHAR2(15)', 22 'NullBooleanField': 'NUMBER(1) CHECK ((%( column)s IN (0,1)) OR (%(column)s IS NULL))',26 'NullBooleanField': 'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(column)s IS NULL))', 23 27 'OneToOneField': 'NUMBER(11)', 24 28 'PhoneNumberField': 'VARCHAR2(20)', 25 'PositiveIntegerField': 'NUMBER(11) CHECK (%( column)s >= 0)',26 'PositiveSmallIntegerField': 'NUMBER(11) CHECK (%( column)s >= 0)',29 'PositiveIntegerField': 'NUMBER(11) CHECK (%(qn_column)s >= 0)', 30 'PositiveSmallIntegerField': 'NUMBER(11) CHECK (%(qn_column)s >= 0)', 27 31 'SlugField': 'NVARCHAR2(50)', 28 32 'SmallIntegerField': 'NUMBER(11)', django/trunk/django/db/models/fields/__init__.py
r7643 r7743 17 17 from django import newforms as forms 18 18 from django.core.exceptions import ObjectDoesNotExist 19 from django.utils.datastructures import DictWrapper 19 20 from django.utils.functional import curry 20 21 from django.utils.itercompat import tee … … 162 163 # can implement db_type() instead of get_internal_type() to specify 163 164 # exactly which wacky database column type you want to use. 165 data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_") 164 166 try: 165 return get_creation_module().DATA_TYPES[self.get_internal_type()] % self.__dict__167 return get_creation_module().DATA_TYPES[self.get_internal_type()] % data 166 168 except KeyError: 167 169 return None django/trunk/django/utils/datastructures.py
r7140 r7743 344 344 return dict.__repr__(d) 345 345 return dict.__repr__(self) 346 347 class DictWrapper(dict): 348 """ 349 Wraps accesses to a dictionary so that certain values (those starting with 350 the specified prefix) are passed through a function before being returned. 351 The prefix is removed before looking up the real value. 352 353 Used by the SQL construction code to ensure that values are correctly 354 quoted before being used. 355 """ 356 def __init__(self, data, func, prefix): 357 super(DictWrapper, self).__init__(data) 358 self.func = func 359 self.prefix = prefix 360 361 def __getitem__(self, key): 362 """ 363 Retrieves the real value after stripping the prefix string (if 364 present). If the prefix is present, pass the value through self.func 365 before returning, otherwise return the raw value. 366 """ 367 if key.startswith(self.prefix): 368 use_func = True 369 key = key[len(self.prefix):] 370 else: 371 use_func = False 372 value = super(DictWrapper, self).__getitem__(key) 373 if use_func: 374 return self.func(value) 375 return value 376 django/trunk/tests/regressiontests/queries/models.py
r7741 r7743 123 123 def get_query_set(self): 124 124 qs = super(CustomManager, self).get_query_set() 125 return qs.filter( is_public=True, tag__name='t1')125 return qs.filter(public=True, tag__name='t1') 126 126 127 127 class ManagedModel(models.Model): 128 128 data = models.CharField(max_length=10) 129 129 tag = models.ForeignKey(Tag) 130 is_public = models.BooleanField(default=True)130 public = models.BooleanField(default=True) 131 131 132 132 objects = CustomManager() … … 731 731 Updates that are filtered on the model being updated are somewhat tricky to get 732 732 in MySQL. This exercises that case. 733 >>> mm = ManagedModel.objects.create(data='mm1', tag=t1, is_public=True)733 >>> mm = ManagedModel.objects.create(data='mm1', tag=t1, public=True) 734 734 >>> ManagedModel.objects.update(data='mm') 735 735
