summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/db/managers.txt25
-rw-r--r--docs/topics/db/multi-db.txt16
2 files changed, 22 insertions, 19 deletions
diff --git a/docs/topics/db/managers.txt b/docs/topics/db/managers.txt
index a14616a17c..a8c0d17076 100644
--- a/docs/topics/db/managers.txt
+++ b/docs/topics/db/managers.txt
@@ -108,7 +108,7 @@ example, using this model::
...the statement ``Book.objects.all()`` will return all books in the database.
You can override a ``Manager``\'s base ``QuerySet`` by overriding the
-``Manager.get_query_set()`` method. ``get_query_set()`` should return a
+``Manager.get_queryset()`` method. ``get_queryset()`` should return a
``QuerySet`` with the properties you require.
For example, the following model has *two* ``Manager``\s -- one that returns
@@ -116,8 +116,8 @@ all objects, and one that returns only the books by Roald Dahl::
# First, define the Manager subclass.
class DahlBookManager(models.Manager):
- def get_query_set(self):
- return super(DahlBookManager, self).get_query_set().filter(author='Roald Dahl')
+ def get_queryset(self):
+ return super(DahlBookManager, self).get_queryset().filter(author='Roald Dahl')
# Then hook it into the Book model explicitly.
class Book(models.Model):
@@ -131,7 +131,7 @@ With this sample model, ``Book.objects.all()`` will return all books in the
database, but ``Book.dahl_objects.all()`` will only return the ones written by
Roald Dahl.
-Of course, because ``get_query_set()`` returns a ``QuerySet`` object, you can
+Of course, because ``get_queryset()`` returns a ``QuerySet`` object, you can
use ``filter()``, ``exclude()`` and all the other ``QuerySet`` methods on it.
So these statements are all legal::
@@ -147,12 +147,12 @@ models.
For example::
class MaleManager(models.Manager):
- def get_query_set(self):
- return super(MaleManager, self).get_query_set().filter(sex='M')
+ def get_queryset(self):
+ return super(MaleManager, self).get_queryset().filter(sex='M')
class FemaleManager(models.Manager):
- def get_query_set(self):
- return super(FemaleManager, self).get_query_set().filter(sex='F')
+ def get_queryset(self):
+ return super(FemaleManager, self).get_queryset().filter(sex='F')
class Person(models.Model):
first_name = models.CharField(max_length=50)
@@ -172,9 +172,12 @@ the "default" ``Manager``, and several parts of Django
(including :djadmin:`dumpdata`) will use that ``Manager``
exclusively for that model. As a result, it's a good idea to be careful in
your choice of default manager in order to avoid a situation where overriding
-``get_query_set()`` results in an inability to retrieve objects you'd like to
+``get_queryset()`` results in an inability to retrieve objects you'd like to
work with.
+.. versionchanged:: 1.6
+ The ``get_queryset`` method was previously named ``get_query_set``.
+
.. _managers-for-related-objects:
Using managers for related object access
@@ -379,9 +382,9 @@ to from some other model. In those situations, Django has to be able to see
all the objects for the model it is fetching, so that *anything* which is
referred to can be retrieved.
-If you override the ``get_query_set()`` method and filter out any rows, Django
+If you override the ``get_queryset()`` method and filter out any rows, Django
will return incorrect results. Don't do that. A manager that filters results
-in ``get_query_set()`` is not appropriate for use as an automatic manager.
+in ``get_queryset()`` is not appropriate for use as an automatic manager.
Set ``use_for_related_fields`` when you define the class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt
index 8150e498de..ae23c3d9f3 100644
--- a/docs/topics/db/multi-db.txt
+++ b/docs/topics/db/multi-db.txt
@@ -506,19 +506,19 @@ solution is to use ``db_manager()``, like this::
``db_manager()`` returns a copy of the manager bound to the database you specify.
-Using ``get_query_set()`` with multiple databases
+Using ``get_queryset()`` with multiple databases
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-If you're overriding ``get_query_set()`` on your manager, be sure to
+If you're overriding ``get_queryset()`` on your manager, be sure to
either call the method on the parent (using ``super()``) or do the
appropriate handling of the ``_db`` attribute on the manager (a string
containing the name of the database to use).
For example, if you want to return a custom ``QuerySet`` class from
-the ``get_query_set`` method, you could do this::
+the ``get_queryset`` method, you could do this::
class MyManager(models.Manager):
- def get_query_set(self):
+ def get_queryset(self):
qs = CustomQuerySet(self.model)
if self._db is not None:
qs = qs.using(self._db)
@@ -548,9 +548,9 @@ multiple-database support::
# Tell Django to delete objects from the 'other' database
obj.delete(using=self.using)
- def queryset(self, request):
+ def get_queryset(self, request):
# Tell Django to look for objects on the 'other' database.
- return super(MultiDBModelAdmin, self).queryset(request).using(self.using)
+ return super(MultiDBModelAdmin, self).get_queryset(request).using(self.using)
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
# Tell Django to populate ForeignKey widgets using a query
@@ -573,9 +573,9 @@ Inlines can be handled in a similar fashion. They require three customized metho
class MultiDBTabularInline(admin.TabularInline):
using = 'other'
- def queryset(self, request):
+ def get_queryset(self, request):
# Tell Django to look for inline objects on the 'other' database.
- return super(MultiDBTabularInline, self).queryset(request).using(self.using)
+ return super(MultiDBTabularInline, self).get_queryset(request).using(self.using)
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
# Tell Django to populate ForeignKey widgets using a query