Skip to content

Instantly share code, notes, and snippets.

@amirouche
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirouche/dfead671ee88b16c3a28 to your computer and use it in GitHub Desktop.
Save amirouche/dfead671ee88b16c3a28 to your computer and use it in GitHub Desktop.
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index b607900..c7efd49 100644
--- a/django/db/models/manager.py
+++ b/django/db/models/manager.py
@@ -179,7 +179,14 @@ class BaseManager(six.with_metaclass(RenameManagerMethods)):
Returns a new QuerySet object. Subclasses can override this method to
easily customize the behavior of the Manager.
"""
- return self._queryset_class(self.model, using=self._db, hints=self._hints)
+ queryset = self._queryset_class(self.model, using=self._db, hints=self._hints)
+ try:
+ db = self.model.meta.db
+ except AttributeError:
+ return queryset
+ else:
+ queryset.using(db)
+ return queryset
def all(self):
# We can't proxy this method through the `QuerySet` like we do for the
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment