diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-05-01 00:32:50 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-05-01 00:32:50 +0000 |
| commit | 5922dabea0e622af3f33d17566363a74ff533cd1 (patch) | |
| tree | 2c8d1555299af8c07bd3af2f8a395b624c4ee77f /docs | |
| parent | e5b52f90f0ca2b3b3490c22d869f8c2afc14a526 (diff) | |
gis: Merged revisions 7499,7501-7502,7504,7509-7510 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7511 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/db-api.txt | 23 | ||||
| -rw-r--r-- | docs/request_response.txt | 23 |
2 files changed, 45 insertions, 1 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 ------------------ diff --git a/docs/request_response.txt b/docs/request_response.txt index a4f03b9185..866a697e31 100644 --- a/docs/request_response.txt +++ b/docs/request_response.txt @@ -402,6 +402,27 @@ hard-coded strings. If you use this technique, follow these guidelines: content, you can't use the ``HttpResponse`` instance as a file-like object. Doing so will raise ``Exception``. +Setting headers +~~~~~~~~~~~~~~~ + +To set a header in your response, just treat it like a dictionary:: + + >>> response = HttpResponse() + >>> response['Pragma'] = 'no-cache' + +Telling the browser to treat the response as a file attachment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To tell the browser to treat the response as a file attachment, use the +``mimetype`` argument and set the ``Content-Disposition`` header. For example, +this is how you might return a Microsoft Excel spreadsheet:: + + >>> response = HttpResponse(my_data, mimetype='application/vnd.ms-excel') + >>> response['Content-Disposition'] = 'attachment; filename=foo.xls' + +There's nothing Django-specific about the ``Content-Disposition`` header, but +it's easy to forget the syntax, so we've included it here. + Methods ------- @@ -420,7 +441,7 @@ Methods but since this is actually the value included in the HTTP ``Content-Type`` header, it can also include the character set encoding, which makes it more than just a MIME type specification. If ``mimetype`` is specified - (not None), that value is used. Otherwise, ``content_type`` is used. If + (not ``None``), that value is used. Otherwise, ``content_type`` is used. If neither is given, the ``DEFAULT_CONTENT_TYPE`` setting is used. ``__setitem__(header, value)`` |
