Skip to content

Commit 2ec2404

Browse files
author
ekaplan1
committed
Improved support for accessing models when using multiple databases
1 parent bd5faf0 commit 2ec2404

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

polymorphic/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def __init__(self, *args, **kwargs):
200200
def create_accessor_function_for_model(model, accessor_name):
201201
def accessor_function(self):
202202
objects = getattr(model, "_base_objects", model.objects)
203-
attr = objects.get(pk=self.pk)
203+
using = kwargs.get("using", self._state.db or DEFAULT_DB_ALIAS)
204+
attr = objects.using(using).get(pk=self.pk)
204205
return attr
205206

206207
return accessor_function
@@ -269,3 +270,4 @@ def add_all_sub_models(super_cls, result):
269270
add_all_super_models(self.__class__, result)
270271
add_all_sub_models(self.__class__, result)
271272
return result
273+

0 commit comments

Comments
 (0)