mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Fixed #24911 -- Made BaseManager.get_queryset() allow custom queryset args.
This commit is contained in:
parent
3b81dbe844
commit
4352e865a7
@ -211,7 +211,7 @@ class BaseManager(object):
|
|||||||
Returns a new QuerySet object. Subclasses can override this method to
|
Returns a new QuerySet object. Subclasses can override this method to
|
||||||
easily customize the behavior of the Manager.
|
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):
|
def all(self):
|
||||||
# We can't proxy this method through the `QuerySet` like we do for the
|
# We can't proxy this method through the `QuerySet` like we do for the
|
||||||
|
@ -66,6 +66,12 @@ class BaseCustomManager(models.Manager):
|
|||||||
CustomManager = BaseCustomManager.from_queryset(CustomQuerySet)
|
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)):
|
class DeconstructibleCustomManager(BaseCustomManager.from_queryset(CustomQuerySet)):
|
||||||
|
|
||||||
def __init__(self, a, b, c=1, d=2):
|
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_default_manager = CustomQuerySet.as_manager()
|
||||||
custom_queryset_custom_manager = CustomManager('hello')
|
custom_queryset_custom_manager = CustomManager('hello')
|
||||||
|
custom_init_queryset_manager = CustomInitQuerySet.as_manager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s %s" % (self.first_name, self.last_name)
|
return "%s %s" % (self.first_name, self.last_name)
|
||||||
|
@ -597,3 +597,12 @@ class CustomManagersRegressTestCase(TestCase):
|
|||||||
obj = RelatedModel.objects.get(name="xyzzy")
|
obj = RelatedModel.objects.get(name="xyzzy")
|
||||||
obj.delete()
|
obj.delete()
|
||||||
self.assertEqual(len(OneToOneRestrictedModel.plain_manager.all()), 0)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user