summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/contrib/contenttypes/fields.py4
-rw-r--r--django/contrib/contenttypes/models.py6
2 files changed, 6 insertions, 4 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py
index 1b6abb9818..ce731bf2dd 100644
--- a/django/contrib/contenttypes/fields.py
+++ b/django/contrib/contenttypes/fields.py
@@ -280,7 +280,9 @@ class GenericForeignKey(FieldCacheMixin):
if ct_id is not None:
ct = self.get_content_type(id=ct_id, using=instance._state.db)
try:
- rel_obj = ct.get_object_for_this_type(pk=pk_val)
+ rel_obj = ct.get_object_for_this_type(
+ using=instance._state.db, pk=pk_val
+ )
except ObjectDoesNotExist:
pass
self.set_cached_value(instance, rel_obj)
diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
index 0d98ed3a4d..4f16e6eb69 100644
--- a/django/contrib/contenttypes/models.py
+++ b/django/contrib/contenttypes/models.py
@@ -174,20 +174,20 @@ class ContentType(models.Model):
except LookupError:
return None
- def get_object_for_this_type(self, **kwargs):
+ def get_object_for_this_type(self, using=None, **kwargs):
"""
Return an object of this type for the keyword arguments given.
Basically, this is a proxy around this object_type's get_object() model
method. The ObjectNotExist exception, if thrown, will not be caught,
so code that calls this method should catch it.
"""
- return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
+ return self.model_class()._base_manager.using(using).get(**kwargs)
def get_all_objects_for_this_type(self, **kwargs):
"""
Return all objects of this type for the keyword arguments given.
"""
- return self.model_class()._base_manager.using(self._state.db).filter(**kwargs)
+ return self.model_class()._base_manager.filter(**kwargs)
def natural_key(self):
return (self.app_label, self.model)