diff options
| author | Jason Pellerin <jpellerin@gmail.com> | 2006-12-04 20:29:44 +0000 |
|---|---|---|
| committer | Jason Pellerin <jpellerin@gmail.com> | 2006-12-04 20:29:44 +0000 |
| commit | b7a897eebbd4797c58b004eda7c6a30f9971eac2 (patch) | |
| tree | fd79ac06b0f20909a770a46e2b692fbe506441a2 /django/db | |
| parent | 040f2272e0aec724a36e7abda445b61ee065a8f1 (diff) | |
[multi-db] Merged trunk to [4000]. Some tests still failing.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@4156 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/__init__.py | 8 | ||||
| -rw-r--r-- | django/db/models/base.py | 21 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 13 | ||||
| -rw-r--r-- | django/db/models/loading.py | 2 |
4 files changed, 16 insertions, 28 deletions
diff --git a/django/db/__init__.py b/django/db/__init__.py index 10b8665e6e..d594c8ba35 100644 --- a/django/db/__init__.py +++ b/django/db/__init__.py @@ -73,16 +73,16 @@ class ConnectionInfo(object): def get_introspection_module(self): return __import__('django.db.backends.%s.introspection' % - self.settings.DATABASE_ENGINE, '', '', ['']) + self.settings.DATABASE_ENGINE, {}, {}, ['']) def get_creation_module(self): return __import__('django.db.backends.%s.creation' % - self.settings.DATABASE_ENGINE, '', '', ['']) + self.settings.DATABASE_ENGINE, {}, {}, ['']) def load_backend(self): try: backend = __import__('django.db.backends.%s.base' % - self.settings.DATABASE_ENGINE, '', '', ['']) + self.settings.DATABASE_ENGINE, {}, {}, ['']) except ImportError, e: # The database backend wasn't found. Display a helpful error # message listing all possible database backends. @@ -108,7 +108,7 @@ class ConnectionInfo(object): def runshell(self): __import__('django.db.backends.%s.client' % - self.settings.DATABASE_ENGINE, '', '', [''] + self.settings.DATABASE_ENGINE, {}, {}, [''] ).runshell(self.settings) def reset_queries(self): diff --git a/django/db/models/base.py b/django/db/models/base.py index da957efc2c..231fff95ec 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -383,27 +383,6 @@ class Model(object): setattr(self, cachename, get_image_dimensions(filename)) return getattr(self, cachename) - # Handles setting many-to-many related objects. - # Example: Album.set_songs() - def _set_related_many_to_many(self, rel_class, rel_field, id_list): - id_list = map(int, id_list) # normalize to integers - rel = rel_field.rel.to - m2m_table = rel_field.m2m_db_table() - this_id = self._get_pk_val() - db = self._default_manager.db - connection = db.connection - qn = db.backend.quote_name - cursor = connection.cursor() - cursor.execute("DELETE FROM %s WHERE %s = %%s" % \ - (qn(m2m_table), - qn(rel_field.m2m_column_name())), [this_id]) - sql = "INSERT INTO %s (%s, %s) VALUES (%%s, %%s)" % \ - (qn(m2m_table), - qn(rel_field.m2m_column_name()), - qn(rel_field.m2m_reverse_name())) - cursor.executemany(sql, [(this_id, i) for i in id_list]) - transaction.commit_unless_managed([connection]) - ############################################ # HELPER FUNCTIONS (CURRIED MODEL METHODS) # ############################################ diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index f8f46084ea..df61a3a331 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -457,7 +457,9 @@ class DateField(Field): def get_db_prep_save(self, value): # Casts dates into string format for entry into database. - if value is not None: + if isinstance(value, datetime.datetime): + value = value.date().strftime('%Y-%m-%d') + elif isinstance(value, datetime.date): value = value.strftime('%Y-%m-%d') return Field.get_db_prep_save(self, value) @@ -487,7 +489,7 @@ class DateTimeField(DateField): def pre_save(self, model_instance, add): value = super(DateField, self).pre_save(model_instance, add) - if value is not None: + if isinstance(value, datetime.datetime): # MySQL will throw a warning if microseconds are given, because it # doesn't support microseconds. settings = model_instance._default_manager.db.connection.settings @@ -499,6 +501,13 @@ class DateTimeField(DateField): # Casts dates into string format for entry into database. if value is not None: value = str(value) + elif isinstance(value, datetime.date): + # MySQL will throw a warning if microseconds are given, because it + # doesn't support microseconds. + if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'): + value = datetime.datetime(value.year, value.month, value.day, microsecond=0) + value = str(value) + return Field.get_db_prep_save(self, value) def get_db_prep_lookup(self, lookup_type, value): diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 76952401d5..286d765a4b 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -51,7 +51,7 @@ def get_app(app_label, emptyOK=False): def load_app(app_name): "Loads the app with the provided fully qualified name, and returns the model module." global _app_list - mod = __import__(app_name, '', '', ['models']) + mod = __import__(app_name, {}, {}, ['models']) if not hasattr(mod, 'models'): return None if mod.models not in _app_list: |
