diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index e1bbf6e..135943a 100644
a
|
b
|
class Manager(object):
|
46 | 46 | # Tracks each time a Manager instance is created. Used to retain order. |
47 | 47 | creation_counter = 0 |
48 | 48 | |
49 | | def __init__(self): |
| 49 | def __init__(self, queryset_cls=None): |
50 | 50 | super(Manager, self).__init__() |
51 | 51 | self._set_creation_counter() |
52 | 52 | self.model = None |
53 | 53 | self._inherited = False |
54 | 54 | self._db = None |
| 55 | self._queryset_cls = queryset_cls or QuerySet |
55 | 56 | |
56 | 57 | def contribute_to_class(self, model, name): |
57 | 58 | # TODO: Use weakref because of possible memory leak / circular reference. |
… |
… |
class Manager(object):
|
101 | 102 | ####################### |
102 | 103 | |
103 | 104 | def get_empty_query_set(self): |
104 | | return EmptyQuerySet(self.model, using=self._db) |
| 105 | return self._queryset_cls(self.model, using=self._db).none() |
105 | 106 | |
106 | 107 | def get_query_set(self): |
107 | 108 | """Returns a new QuerySet object. Subclasses can override this method |
108 | 109 | to easily customize the behavior of the Manager. |
109 | 110 | """ |
110 | | return QuerySet(self.model, using=self._db) |
| 111 | return self._queryset_cls(self.model, using=self._db) |
111 | 112 | |
112 | 113 | def none(self): |
113 | 114 | return self.get_empty_query_set() |
diff --git a/django/db/models/query.py b/django/db/models/query.py
index be42d02..e78e9ad 100644
a
|
b
|
class QuerySet(object):
|
582 | 582 | """ |
583 | 583 | Returns an empty QuerySet. |
584 | 584 | """ |
585 | | return self._clone(klass=EmptyQuerySet) |
| 585 | klass = type( |
| 586 | "_InstrumentedEmptyQuerySet_%s" % self.__class__.__name__, |
| 587 | (EmptyQuerySet, self.__class__), {}) |
| 588 | return self._clone(klass=klass) |
586 | 589 | |
587 | 590 | ################################################################## |
588 | 591 | # PUBLIC METHODS THAT ALTER ATTRIBUTES AND RETURN A NEW QUERYSET # |
diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py
index 7c264a4..2506d7a 100644
a
|
b
|
This demonstrates features of the database API.
|
5 | 5 | """ |
6 | 6 | |
7 | 7 | from django.db import models |
| 8 | from django.db.models.query import QuerySet |
8 | 9 | |
| 10 | class CustomArticleQuerySet(QuerySet): |
| 11 | |
| 12 | def have_author1(self): |
| 13 | return self.filter(author__name='Author 1') |
9 | 14 | |
10 | 15 | class Author(models.Model): |
11 | 16 | name = models.CharField(max_length=100) |
… |
… |
class Author(models.Model):
|
13 | 18 | ordering = ('name', ) |
14 | 19 | |
15 | 20 | class Article(models.Model): |
| 21 | objects = models.Manager() |
| 22 | custom_manager = models.Manager(CustomArticleQuerySet) |
| 23 | |
16 | 24 | headline = models.CharField(max_length=100) |
17 | 25 | pub_date = models.DateTimeField() |
18 | 26 | author = models.ForeignKey(Author, blank=True, null=True) |
diff --git a/tests/modeltests/lookup/tests.py b/tests/modeltests/lookup/tests.py
index 9c2b0c6..e12f3f3 100644
a
|
b
|
class LookupTests(TestCase):
|
450 | 450 | [article for article in Article.objects.none().iterator()], |
451 | 451 | []) |
452 | 452 | |
| 453 | def test_none_custom_qs(self): |
| 454 | self.assertQuerysetEqual(Article.custom_manager.none(), []) |
| 455 | self.assertQuerysetEqual( |
| 456 | Article.custom_manager.none().have_author1(), |
| 457 | []) |
| 458 | |
453 | 459 | def test_in(self): |
454 | 460 | # using __in with an empty list should return an empty query set |
455 | 461 | self.assertQuerysetEqual(Article.objects.filter(id__in=[]), []) |