diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-03-13 00:36:57 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-03-13 00:36:57 +0000 |
| commit | 9f0fb3dcc9d24ec1f5abb83dfb58b6da5a6d4baa (patch) | |
| tree | feed3b2ce901c56729c8218d5199a3f8f18e436a | |
| parent | c8b33b824b4532e0f81abeb095764b0e3ea3c2e1 (diff) | |
queryset-refactor: Made none() a method on Querysets, as the documentation
indicates (it was only added to managers in [4394]. Refs #6177.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7232 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/query.py | 6 | ||||
| -rw-r--r-- | tests/modeltests/lookup/models.py | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 59b6e64954..76f5eab680 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -293,6 +293,12 @@ class _QuerySet(object): return self._clone(klass=DateQuerySet, setup=True, _field=field, _kind=kind, _order=order) + def none(self): + """ + Returns an empty queryset. + """ + return self._clone(klass=EmptyQuerySet) + ################################################################## # 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 a87ce523a2..f3cce70e12 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -254,6 +254,8 @@ DoesNotExist: Article matching query does not exist. [] >>> Article.objects.none().filter(headline__startswith='Article') [] +>>> Article.objects.filter(headline__startswith='Article').none() +[] >>> Article.objects.none().count() 0 >>> [article for article in Article.objects.none().iterator()] |
