summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2008-04-28 14:43:46 +0000
committerBrian Rosner <brosner@gmail.com>2008-04-28 14:43:46 +0000
commit886005078d66bd779ad3d6434d5699fbc17cfed1 (patch)
treea8b94b81b22e84b8223c37de2c00710a3b221f02 /docs
parent738e6d986ba41ec5ef9ba5a600a333916f2e763d (diff)
newforms-admin: Merged from trunk up to [7499].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7500 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/db-api.txt23
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/db-api.txt b/docs/db-api.txt
index 6299f3497d..405ed87cef 100644
--- a/docs/db-api.txt
+++ b/docs/db-api.txt
@@ -376,6 +376,29 @@ You can evaluate a ``QuerySet`` in the following ways:
iterating over a ``QuerySet`` will take advantage of your database to
load data and instantiate objects only as you need them.
+
+Pickling QuerySets
+~~~~~~~~~~~~~~~~~~
+
+If you pickle_ a ``QuerySet``, this will also force all the results to be
+loaded into memory prior to pickling. This is because pickling is usually used
+as a precursor to caching and when the cached queryset is reloaded, you want
+the results to already be present. This means that when you unpickle a
+``QuerySet``, it contains the results at the moment it was pickled, rather
+than the results that are currently in the database.
+
+If you only want to pickle the necessary information to recreate the
+``Queryset`` from the database at a later time, pickle the ``query`` attribute
+of the ``QuerySet``. You can then recreate the original ``QuerySet`` (without
+any results loaded) using some code like this::
+
+ >>> import pickle
+ >>> query = pickle.loads(s) # Assuming 's' is the pickled string.
+ >>> qs = MyModel.objects.all()
+ >>> qs.query = query # Restore the original 'query'.
+
+.. _pickle: http://docs.python.org/lib/module-pickle.html
+
Limiting QuerySets
------------------