Fixed #24911 -- Made BaseManager.get_queryset() allow custom queryset args.

This commit is contained in:
Jonas Degrave 2015-06-04 01:13:39 +02:00 committed by Tim Graham
parent 3b81dbe844
commit 4352e865a7
3 changed files with 17 additions and 1 deletions

View File

@ -211,7 +211,7 @@ class BaseManager(object):
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)
return self._queryset_class(model=self.model, using=self._db, hints=self._hints)
def all(self):
# We can't proxy this method through the `QuerySet` like we do for the

View File

@ -66,6 +66,12 @@ class BaseCustomManager(models.Manager):
CustomManager = BaseCustomManager.from_queryset(CustomQuerySet)
class CustomInitQuerySet(models.QuerySet):
# QuerySet with an __init__() method that takes an additional argument.
def __init__(self, custom_optional_arg=None, model=None, query=None, using=None, hints=None):
super(CustomInitQuerySet, self).__init__(model=model, query=query, using=using, hints=hints)
class DeconstructibleCustomManager(BaseCustomManager.from_queryset(CustomQuerySet)):
def __init__(self, a, b, c=1, d=2):
@ -99,6 +105,7 @@ class Person(models.Model):
custom_queryset_default_manager = CustomQuerySet.as_manager()
custom_queryset_custom_manager = CustomManager('hello')
custom_init_queryset_manager = CustomInitQuerySet.as_manager()
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)

View File

@ -597,3 +597,12 @@ class CustomManagersRegressTestCase(TestCase):
obj = RelatedModel.objects.get(name="xyzzy")
obj.delete()
self.assertEqual(len(OneToOneRestrictedModel.plain_manager.all()), 0)
def test_queryset_with_custom_init(self):
"""
BaseManager.get_queryset() should use kwargs rather than args to allow
custom kwargs (#24911).
"""
qs_custom = Person.custom_init_queryset_manager.all()
qs_default = Person.objects.all()
self.assertQuerysetEqual(qs_custom, qs_default)