Fixed #4303 -- Fixed typos in docs/db-api.txt. Thanks, Gary Wilson

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5253 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-05-15 19:35:53 +00:00
parent 72e824ad14
commit 6f44cffc77
1 changed files with 25 additions and 25 deletions

View File

@ -143,8 +143,8 @@ or ``UPDATE`` SQL statements. Specifically, when you call ``save()``, Django
follows this algorithm: follows this algorithm:
* If the object's primary key attribute is set to a value that evaluates to * If the object's primary key attribute is set to a value that evaluates to
``True`` (i.e., a value other than ``None`` or the empty string), Django ``True`` (i.e., a value other than ``None`` or the empty string), Django
executes a ``SELECT`` query to determine whether a record with the given executes a ``SELECT`` query to determine whether a record with the given
primary key already exists. primary key already exists.
* If the record with the given primary key does already exist, Django * If the record with the given primary key does already exist, Django
executes an ``UPDATE`` query. executes an ``UPDATE`` query.
@ -525,19 +525,19 @@ Examples::
[datetime.datetime(2005, 3, 20), datetime.datetime(2005, 2, 20)] [datetime.datetime(2005, 3, 20), datetime.datetime(2005, 2, 20)]
>>> Entry.objects.filter(headline__contains='Lennon').dates('pub_date', 'day') >>> Entry.objects.filter(headline__contains='Lennon').dates('pub_date', 'day')
[datetime.datetime(2005, 3, 20)] [datetime.datetime(2005, 3, 20)]
``none()`` ``none()``
~~~~~~~~~~ ~~~~~~~~~~
**New in Django development version** **New in Django development version**
Returns an ``EmptyQuerySet`` -- a ``QuerySet`` that always evaluates to Returns an ``EmptyQuerySet`` -- a ``QuerySet`` that always evaluates to
an empty list. This can be used in cases where you know that you should an empty list. This can be used in cases where you know that you should
return an empty result set and your caller is expecting a ``QuerySet`` return an empty result set and your caller is expecting a ``QuerySet``
object (instead of returning an empty list, for example.) object (instead of returning an empty list, for example.)
Examples:: Examples::
>>> Entry.objects.none() >>> Entry.objects.none()
[] []
@ -610,7 +610,7 @@ follow::
c = p.hometown # Requires a database call. c = p.hometown # Requires a database call.
The ``depth`` argument is new in the Django development version. The ``depth`` argument is new in the Django development version.
``extra(select=None, where=None, params=None, tables=None)`` ``extra(select=None, where=None, params=None, tables=None)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -1136,7 +1136,7 @@ such as January 3, July 3, etc.
isnull isnull
~~~~~~ ~~~~~~
Takes either ``True`` or ``False``, which correspond to SQL queries of Takes either ``True`` or ``False``, which correspond to SQL queries of
``IS NULL`` and ``IS NOT NULL``, respectively. ``IS NULL`` and ``IS NOT NULL``, respectively.
Example:: Example::
@ -1149,10 +1149,10 @@ SQL equivalent::
.. admonition:: ``__isnull=True`` vs ``__exact=None`` .. admonition:: ``__isnull=True`` vs ``__exact=None``
There is an important difference between ``__isnull=True`` and There is an important difference between ``__isnull=True`` and
``__exact=None``. ``__exact=None`` will *always* return an empty result ``__exact=None``. ``__exact=None`` will *always* return an empty result
set, because SQL requires that no value is equal to ``NULL``. set, because SQL requires that no value is equal to ``NULL``.
``__isnull`` determines if the field is currently holding the value ``__isnull`` determines if the field is currently holding the value
of ``NULL`` without performing a comparison. of ``NULL`` without performing a comparison.
search search
@ -1181,7 +1181,7 @@ The pk lookup shortcut
---------------------- ----------------------
For convenience, Django provides a ``pk`` lookup type, which stands for For convenience, Django provides a ``pk`` lookup type, which stands for
"primary_key". "primary_key".
In the example ``Blog`` model, the primary key is the ``id`` field, so these In the example ``Blog`` model, the primary key is the ``id`` field, so these
three statements are equivalent:: three statements are equivalent::
@ -1190,14 +1190,14 @@ three statements are equivalent::
Blog.objects.get(id=14) # __exact is implied Blog.objects.get(id=14) # __exact is implied
Blog.objects.get(pk=14) # pk implies id__exact Blog.objects.get(pk=14) # pk implies id__exact
The use of ``pk`` isn't limited to ``__exact`` queries -- any query term The use of ``pk`` isn't limited to ``__exact`` queries -- any query term
can be combined with ``pk`` to perform a query on the primary key of a model:: can be combined with ``pk`` to perform a query on the primary key of a model::
# Get blogs entries with id 1, 4 and 7 # Get blogs entries with id 1, 4 and 7
Blog.objects.filter(pk__in=[1,4,7]) Blog.objects.filter(pk__in=[1,4,7])
# Get all blog entries with id > 14 # Get all blog entries with id > 14
Blog.objects.filter(pk__gt=14) Blog.objects.filter(pk__gt=14)
``pk`` lookups also work across joins. For example, these three statements are ``pk`` lookups also work across joins. For example, these three statements are
equivalent:: equivalent::
@ -1754,19 +1754,19 @@ get_object_or_404()
------------------- -------------------
One common idiom to use ``get()`` and raise ``Http404`` if the One common idiom to use ``get()`` and raise ``Http404`` if the
object doesn't exist. This idiom is captured by ``get_object_or_404()``. object doesn't exist. This idiom is captured by ``get_object_or_404()``.
This function takes a Django model as its first argument and an This function takes a Django model as its first argument and an
arbitrary number of keyword arguments, which it passes to the manager's arbitrary number of keyword arguments, which it passes to the manager's
``get()`` function. It raises ``Http404`` if the object doesn't ``get()`` function. It raises ``Http404`` if the object doesn't
exist. For example:: exist. For example::
# Get the Entry with a primary key of 3 # Get the Entry with a primary key of 3
e = get_object_or_404(Entry, pk=3) e = get_object_or_404(Entry, pk=3)
When you provide a model to this shortcut function, the default manager When you provide a model to this shortcut function, the default manager
is used to execute the underlying ``get()`` query. If you don't want to is used to execute the underlying ``get()`` query. If you don't want to
use the default manager, or you want to search a list of related objects, use the default manager, or if you want to search a list of related objects,
you can provide ``get_object_or_404()`` with a manager object, instead. you can provide ``get_object_or_404()`` with a manager object instead.
For example:: For example::
# Get the author of blog instance `e` with a name of 'Fred' # Get the author of blog instance `e` with a name of 'Fred'
@ -1779,8 +1779,8 @@ For example::
get_list_or_404() get_list_or_404()
----------------- -----------------
``get_list_or_404`` behaves the same was as ``get_object_or_404()`` ``get_list_or_404`` behaves the same way as ``get_object_or_404()``
-- except that it uses using ``filter()`` instead of ``get()``. It raises -- except that it uses ``filter()`` instead of ``get()``. It raises
``Http404`` if the list is empty. ``Http404`` if the list is empty.
Falling back to raw SQL Falling back to raw SQL