diff options
| author | Tom Carrick <knyght@knyg.ht> | 2017-03-28 16:57:23 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-21 08:34:35 -0400 |
| commit | 3159ad4df6ec05c3eac07b930b4af32739bec7b0 (patch) | |
| tree | 37c97dc6f7425b8f8529e5f4d21e38a2cbe2b5e5 /docs | |
| parent | 76236f0db2d6afe14c08393cef676f0f3939f7d8 (diff) | |
Fixed #27970 -- Allowed QuerySet.in_bulk() to fetch on fields besides primary key.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/querysets.txt | 16 | ||||
| -rw-r--r-- | docs/releases/2.0.txt | 3 |
2 files changed, 15 insertions, 4 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 2c1f68fc06..74f83ab8c5 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1997,11 +1997,13 @@ database query like ``count()`` would. ``in_bulk()`` ~~~~~~~~~~~~~ -.. method:: in_bulk(id_list=None) +.. method:: in_bulk(id_list=None, field_name='pk') -Takes a list of primary-key values and returns a dictionary mapping each -primary-key value to an instance of the object with the given ID. If a list -isn't provided, all objects in the queryset are returned. +Takes a list of field values (``id_list``) and the ``field_name`` for those +values, and returns a dictionary mapping each value to an instance of the +object with the given field value. If ``id_list`` isn't provided, all objects +in the queryset are returned. ``field_name`` must be a unique field, and it +defaults to the primary key. Example:: @@ -2013,9 +2015,15 @@ Example:: {} >>> Blog.objects.in_bulk() {1: <Blog: Beatles Blog>, 2: <Blog: Cheddar Talk>, 3: <Blog: Django Weblog>} + >>> Blog.objects.in_bulk(['beatles_blog'], field_name='slug') + {'beatles_blog': <Blog: Beatles Blog>} If you pass ``in_bulk()`` an empty list, you'll get an empty dictionary. +.. versionchanged:: 2.0 + + The ``field_name`` parameter was added. + ``iterator()`` ~~~~~~~~~~~~~~ diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 16024ae244..162ac42306 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -259,6 +259,9 @@ Models :meth:`~.QuerySet.select_for_update()` is used in conjunction with :meth:`~.QuerySet.select_related()`. +* The new ``field_name`` parameter of :meth:`.QuerySet.in_bulk` allows fetching + results based on any unique model field. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ |
