Commits

Anonymous committed 0faa408

[soc2010/query-refactor] Fixed a number of issues under postgresql.

Comments (0)

Files changed (3)

django/db/backends/__init__.py

                 if not router.allow_syncdb(self.connection.alias, model):
                     continue
                 for f in model._meta.local_fields:
-                    if isinstance(f, models.AutoField):
+                    if isinstance(f, models.BaseAutoField):
                         sequence_list.append({'table': model._meta.db_table, 'column': f.column})
                         break # Only one AutoField is allowed per model, so don't bother continuing.
 

django/db/backends/postgresql/operations.py

 # used by both the 'postgresql' and 'postgresql_psycopg2' backends.
 
 class DatabaseOperations(BaseDatabaseOperations):
-    def __init__(self, connection):
-        super(DatabaseOperations, self).__init__()
+    def __init__(self, *args, **kwargs):
+        super(DatabaseOperations, self).__init__(*args, **kwargs)
         self._postgres_version = None
-        self.connection = connection
 
     def _get_postgres_version(self):
         if self._postgres_version is None:
             # and column name (available since PostgreSQL 8)
 
             for f in model._meta.local_fields:
-                if isinstance(f, models.AutoField):
+                if isinstance(f, models.BaseAutoField):
                     output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
                         (style.SQL_KEYWORD('SELECT'),
                         style.SQL_TABLE(model._meta.db_table),

django/db/models/base.py

 import django.db.models.manager     # Imported to register signal handler.
 from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS
 from django.core import validators
-from django.db.models.fields import AutoField, FieldDoesNotExist
+from django.db.models.fields import BaseAutoField, FieldDoesNotExist
 from django.db.models.fields.related import OneToOneRel, ManyToOneRel, OneToOneField
 from django.db.models.query import delete_objects, Q
 from django.db.models.query_utils import CollectedObjects, DeferredAttribute
                 if not pk_set:
                     if force_update:
                         raise ValueError("Cannot force an update in save() with no primary key.")
-                    values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True), connection=connection))
-                        for f in meta.local_fields if not isinstance(f, AutoField)]
+                    values = [
+                        (f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True), connection=connection))
+                        for f in meta.local_fields if not isinstance(f, BaseAutoField)
+                    ]
                 else:
                     values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True), connection=connection))
                         for f in meta.local_fields]