commit 4f8356075d59ea4904b38d3e99f2806fb07e03c2
Author: Jonas Haag <jonas@lophus.org>
Date: Wed Sep 28 21:47:11 2011 +0200
Merge Alex Gaynor's GSoC branch
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index ce1da6d..a0089ca 100644
a
|
b
|
import sys
|
2 | 2 | import time |
3 | 3 | |
4 | 4 | from django.conf import settings |
| 5 | from django.utils.datastructures import DictWrapper |
5 | 6 | |
6 | 7 | # The prefix to put on the default database name when creating |
7 | 8 | # the test database. |
… |
… |
class BaseDatabaseCreation(object):
|
26 | 27 | """ |
27 | 28 | return '%x' % (abs(hash(args)) % 4294967296L) # 2**32 |
28 | 29 | |
| 30 | def db_type(self, field): |
| 31 | return self._db_type(field, field.get_internal_type()) |
| 32 | |
| 33 | def related_db_type(self, field): |
| 34 | return self._db_type(field, field.get_related_internal_type()) |
| 35 | |
| 36 | def _db_type(self, field, internal_type): |
| 37 | data = DictWrapper(field.__dict__, self.connection.ops.quote_name, "qn_") |
| 38 | try: |
| 39 | return self.connection.creation.data_types[internal_type] % data |
| 40 | except KeyError: |
| 41 | return None |
| 42 | |
29 | 43 | def sql_create_model(self, model, style, known_models=set()): |
30 | 44 | """ |
31 | 45 | Returns the SQL required to create a single model, as a tuple of: |
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index 93aaf99..472979a 100644
a
|
b
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
366 | 366 | |
367 | 367 | def _rollback(self): |
368 | 368 | try: |
369 | | BaseDatabaseWrapper._rollback(self) |
| 369 | super(DatabaseWrapper, self)._rollback() |
370 | 370 | except Database.NotSupportedError: |
371 | 371 | pass |
372 | 372 | |
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index a610606..92875cb 100644
a
|
b
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
289 | 289 | # database. To prevent accidental data loss, ignore close requests on |
290 | 290 | # an in-memory db. |
291 | 291 | if self.settings_dict['NAME'] != ":memory:": |
292 | | BaseDatabaseWrapper.close(self) |
| 292 | super(DatabaseWrapper, self).close() |
293 | 293 | |
294 | 294 | FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s') |
295 | 295 | |
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 04b13aa..bdb8233 100644
a
|
b
|
from django.db.models.query_utils import QueryWrapper
|
10 | 10 | from django.conf import settings |
11 | 11 | from django import forms |
12 | 12 | from django.core import exceptions, validators |
13 | | from django.utils.datastructures import DictWrapper |
14 | 13 | from django.utils.dateparse import parse_date, parse_datetime, parse_time |
15 | 14 | from django.utils.functional import curry |
16 | 15 | from django.utils.text import capfirst |
… |
… |
class Field(object):
|
221 | 220 | # mapped to one of the built-in Django field types. In this case, you |
222 | 221 | # can implement db_type() instead of get_internal_type() to specify |
223 | 222 | # exactly which wacky database column type you want to use. |
224 | | data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_") |
225 | | try: |
226 | | return (connection.creation.data_types[self.get_internal_type()] |
227 | | % data) |
228 | | except KeyError: |
229 | | return None |
| 223 | return connection.creation.db_type(self) |
| 224 | |
| 225 | def related_db_type(self, connection): |
| 226 | # This is the db_type used by a ForeignKey. |
| 227 | return connection.creation.related_db_type(self) |
230 | 228 | |
231 | 229 | @property |
232 | 230 | def unique(self): |
… |
… |
class Field(object):
|
261 | 259 | def get_internal_type(self): |
262 | 260 | return self.__class__.__name__ |
263 | 261 | |
| 262 | def get_related_internal_type(self): |
| 263 | return self.get_internal_type() |
| 264 | |
264 | 265 | def pre_save(self, model_instance, add): |
265 | 266 | """ |
266 | 267 | Returns field's value just before saving. |
… |
… |
class AutoField(Field):
|
518 | 519 | def get_internal_type(self): |
519 | 520 | return "AutoField" |
520 | 521 | |
| 522 | def get_related_internal_type(self): |
| 523 | return "RelatedAutoField" |
| 524 | |
| 525 | def related_db_type(self, connection): |
| 526 | db_type = super(AutoField, self).related_db_type(connection=connection) |
| 527 | if db_type is None: |
| 528 | return IntegerField().db_type(connection=connection) |
| 529 | return db_type |
| 530 | |
521 | 531 | def to_python(self, value): |
522 | 532 | if value is None: |
523 | 533 | return value |