mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
[multi-db] Updated related fields to get db connection from model._default_manager.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3366 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
62306542ee
commit
8b77fe3195
@ -316,7 +316,7 @@ def create_many_related_manager(superclass):
|
|||||||
# source_col_name: the PK colname in join_table for the source object
|
# source_col_name: the PK colname in join_table for the source object
|
||||||
# target_col_name: the PK colname in join_table for the target object
|
# target_col_name: the PK colname in join_table for the target object
|
||||||
# *objs - objects to add
|
# *objs - objects to add
|
||||||
connection = self.model._meta.connection
|
connection = self.model._default_manager.db.connection
|
||||||
|
|
||||||
# Add the newly created or already existing objects to the join table.
|
# Add the newly created or already existing objects to the join table.
|
||||||
# First find out which items are already added, to avoid adding them twice
|
# First find out which items are already added, to avoid adding them twice
|
||||||
@ -342,7 +342,7 @@ def create_many_related_manager(superclass):
|
|||||||
# source_col_name: the PK colname in join_table for the source object
|
# source_col_name: the PK colname in join_table for the source object
|
||||||
# target_col_name: the PK colname in join_table for the target object
|
# target_col_name: the PK colname in join_table for the target object
|
||||||
# *objs - objects to remove
|
# *objs - objects to remove
|
||||||
connection = self.model._meta.connection
|
connection = self.model._default_manager.db.connection
|
||||||
|
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
if not isinstance(obj, self.model):
|
if not isinstance(obj, self.model):
|
||||||
@ -357,7 +357,7 @@ def create_many_related_manager(superclass):
|
|||||||
|
|
||||||
def _clear_items(self, source_col_name):
|
def _clear_items(self, source_col_name):
|
||||||
# source_col_name: the PK colname in join_table for the source object
|
# source_col_name: the PK colname in join_table for the source object
|
||||||
connection = self.model._meta.connection
|
connection = self.model._default_manager.db.connection
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute("DELETE FROM %s WHERE %s = %%s" % \
|
cursor.execute("DELETE FROM %s WHERE %s = %%s" % \
|
||||||
(self.join_table, source_col_name),
|
(self.join_table, source_col_name),
|
||||||
@ -386,8 +386,7 @@ class ManyRelatedObjectsDescriptor(object):
|
|||||||
superclass = rel_model._default_manager.__class__
|
superclass = rel_model._default_manager.__class__
|
||||||
RelatedManager = create_many_related_manager(superclass)
|
RelatedManager = create_many_related_manager(superclass)
|
||||||
|
|
||||||
backend = rel_model._meta.connection_info.backend
|
qn = rel_model._default_manager.db.backend.quote_name
|
||||||
qn = backend.quote_name
|
|
||||||
manager = RelatedManager(
|
manager = RelatedManager(
|
||||||
model=rel_model,
|
model=rel_model,
|
||||||
core_filters={'%s__pk' % self.related.field.name: instance._get_pk_val()},
|
core_filters={'%s__pk' % self.related.field.name: instance._get_pk_val()},
|
||||||
@ -429,8 +428,7 @@ class ReverseManyRelatedObjectsDescriptor(object):
|
|||||||
superclass = rel_model._default_manager.__class__
|
superclass = rel_model._default_manager.__class__
|
||||||
RelatedManager = create_many_related_manager(superclass)
|
RelatedManager = create_many_related_manager(superclass)
|
||||||
|
|
||||||
backend = rel_model._meta.connection_info.backend
|
qn = rel_model._default_manager.db.backend.quote_name
|
||||||
qn = backend.quote_name
|
|
||||||
manager = RelatedManager(
|
manager = RelatedManager(
|
||||||
model=rel_model,
|
model=rel_model,
|
||||||
core_filters={'%s__pk' % self.field.related_query_name(): instance._get_pk_val()},
|
core_filters={'%s__pk' % self.field.related_query_name(): instance._get_pk_val()},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user