mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
[soc2010/query-refactor] Fixed a number of issues under postgresql.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13408 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
183c290b83
commit
7dcb95ae9a
@ -560,7 +560,7 @@ class BaseDatabaseIntrospection(object):
|
|||||||
if not router.allow_syncdb(self.connection.alias, model):
|
if not router.allow_syncdb(self.connection.alias, model):
|
||||||
continue
|
continue
|
||||||
for f in model._meta.local_fields:
|
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})
|
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
|
||||||
break # Only one AutoField is allowed per model, so don't bother continuing.
|
break # Only one AutoField is allowed per model, so don't bother continuing.
|
||||||
|
|
||||||
|
@ -6,10 +6,9 @@ from django.db.backends import BaseDatabaseOperations
|
|||||||
# used by both the 'postgresql' and 'postgresql_psycopg2' backends.
|
# used by both the 'postgresql' and 'postgresql_psycopg2' backends.
|
||||||
|
|
||||||
class DatabaseOperations(BaseDatabaseOperations):
|
class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def __init__(self, connection):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseOperations, self).__init__()
|
super(DatabaseOperations, self).__init__(*args, **kwargs)
|
||||||
self._postgres_version = None
|
self._postgres_version = None
|
||||||
self.connection = connection
|
|
||||||
|
|
||||||
def _get_postgres_version(self):
|
def _get_postgres_version(self):
|
||||||
if self._postgres_version is None:
|
if self._postgres_version is None:
|
||||||
@ -117,7 +116,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||||||
# and column name (available since PostgreSQL 8)
|
# and column name (available since PostgreSQL 8)
|
||||||
|
|
||||||
for f in model._meta.local_fields:
|
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;" % \
|
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_KEYWORD('SELECT'),
|
||||||
style.SQL_TABLE(model._meta.db_table),
|
style.SQL_TABLE(model._meta.db_table),
|
||||||
|
@ -5,7 +5,7 @@ from itertools import izip
|
|||||||
import django.db.models.manager # Imported to register signal handler.
|
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.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS
|
||||||
from django.core import validators
|
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.fields.related import OneToOneRel, ManyToOneRel, OneToOneField
|
||||||
from django.db.models.query import delete_objects, Q
|
from django.db.models.query import delete_objects, Q
|
||||||
from django.db.models.query_utils import CollectedObjects, DeferredAttribute
|
from django.db.models.query_utils import CollectedObjects, DeferredAttribute
|
||||||
@ -514,8 +514,10 @@ class Model(object):
|
|||||||
if not pk_set:
|
if not pk_set:
|
||||||
if force_update:
|
if force_update:
|
||||||
raise ValueError("Cannot force an update in save() with no primary key.")
|
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))
|
values = [
|
||||||
for f in meta.local_fields if not isinstance(f, AutoField)]
|
(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:
|
else:
|
||||||
values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True), connection=connection))
|
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]
|
for f in meta.local_fields]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user