Changeset 5259
- Timestamp:
- 05/16/07 11:30:51 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/boulder-oracle-sprint/docs/db-api.txt
r5128 r5259 144 144 145 145 * If the object's primary key attribute is set to a value that evaluates to 146 ``True`` (i.e., a value other than ``None`` or the empty string), Django 147 executes a ``SELECT`` query to determine whether a record with the given 146 ``True`` (i.e., a value other than ``None`` or the empty string), Django 147 executes a ``SELECT`` query to determine whether a record with the given 148 148 primary key already exists. 149 149 * If the record with the given primary key does already exist, Django … … 526 526 >>> Entry.objects.filter(headline__contains='Lennon').dates('pub_date', 'day') 527 527 [datetime.datetime(2005, 3, 20)] 528 528 529 529 ``none()`` 530 530 ~~~~~~~~~~ … … 532 532 **New in Django development version** 533 533 534 Returns an ``EmptyQuerySet`` -- a ``QuerySet`` that always evaluates to 534 Returns an ``EmptyQuerySet`` -- a ``QuerySet`` that always evaluates to 535 535 an empty list. This can be used in cases where you know that you should 536 536 return an empty result set and your caller is expecting a ``QuerySet`` … … 538 538 539 539 Examples:: 540 540 541 541 >>> Entry.objects.none() 542 542 [] … … 611 611 612 612 The ``depth`` argument is new in the Django development version. 613 613 614 614 ``extra(select=None, where=None, params=None, tables=None)`` 615 615 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 1137 1137 ~~~~~~ 1138 1138 1139 Takes either ``True`` or ``False``, which correspond to SQL queries of 1139 Takes either ``True`` or ``False``, which correspond to SQL queries of 1140 1140 ``IS NULL`` and ``IS NOT NULL``, respectively. 1141 1141 … … 1150 1150 .. admonition:: ``__isnull=True`` vs ``__exact=None`` 1151 1151 1152 There is an important difference between ``__isnull=True`` and 1152 There is an important difference between ``__isnull=True`` and 1153 1153 ``__exact=None``. ``__exact=None`` will *always* return an empty result 1154 set, because SQL requires that no value is equal to ``NULL``. 1155 ``__isnull`` determines if the field is currently holding the value 1154 set, because SQL requires that no value is equal to ``NULL``. 1155 ``__isnull`` determines if the field is currently holding the value 1156 1156 of ``NULL`` without performing a comparison. 1157 1157 … … 1182 1182 1183 1183 For convenience, Django provides a ``pk`` lookup type, which stands for 1184 "primary_key". 1184 "primary_key". 1185 1185 1186 1186 In the example ``Blog`` model, the primary key is the ``id`` field, so these … … 1191 1191 Blog.objects.get(pk=14) # pk implies id__exact 1192 1192 1193 The use of ``pk`` isn't limited to ``__exact`` queries -- any query term 1193 The use of ``pk`` isn't limited to ``__exact`` queries -- any query term 1194 1194 can be combined with ``pk`` to perform a query on the primary key of a model:: 1195 1195 … … 1197 1197 Blog.objects.filter(pk__in=[1,4,7]) 1198 1198 # Get all blog entries with id > 14 1199 Blog.objects.filter(pk__gt=14) 1200 1199 Blog.objects.filter(pk__gt=14) 1200 1201 1201 ``pk`` lookups also work across joins. For example, these three statements are 1202 1202 equivalent:: … … 1755 1755 1756 1756 One common idiom to use ``get()`` and raise ``Http404`` if the 1757 object doesn't exist. This idiom is captured by ``get_object_or_404()``. 1758 This function takes a Django model as its first argument and an 1759 arbitrary number of keyword arguments, which it passes to the manager's 1757 object doesn't exist. This idiom is captured by ``get_object_or_404()``. 1758 This function takes a Django model as its first argument and an 1759 arbitrary number of keyword arguments, which it passes to the manager's 1760 1760 ``get()`` function. It raises ``Http404`` if the object doesn't 1761 exist. For example:: 1762 1761 exist. For example:: 1762 1763 1763 # Get the Entry with a primary key of 3 1764 1764 e = get_object_or_404(Entry, pk=3) 1765 1765 1766 When you provide a model to this shortcut function, the default manager 1767 is used to execute the underlying ``get()`` query. If you don't want to 1768 use the default manager, or you want to search a list of related objects,1769 you can provide ``get_object_or_404()`` with a manager object , instead.1766 When you provide a model to this shortcut function, the default manager 1767 is used to execute the underlying ``get()`` query. If you don't want to 1768 use the default manager, or if you want to search a list of related objects, 1769 you can provide ``get_object_or_404()`` with a manager object instead. 1770 1770 For example:: 1771 1771 … … 1780 1780 ----------------- 1781 1781 1782 ``get_list_or_404`` behaves the same wa s as ``get_object_or_404()``1783 -- except th e it uses using ``filter()`` instead of ``get()``. It raises1782 ``get_list_or_404`` behaves the same way as ``get_object_or_404()`` 1783 -- except that it uses ``filter()`` instead of ``get()``. It raises 1784 1784 ``Http404`` if the list is empty. 1785 1785 django/branches/boulder-oracle-sprint/docs/model-api.txt
r5174 r5259 1760 1760 <a href="{{ object.get_absolute_url }}">{{ object.name }}</a> 1761 1761 1762 .. note:: 1763 The string you return from ``get_absolute_url()`` must be use only ASCII 1764 characters (required by the URI spec, `RFC 2396`_) that has been 1765 URL-encoded, if necessary. Code and templates using ``get_absolute_url()`` 1766 should be able to use the result directly without needing to do any 1767 further processing. 1768 1769 .. _RFC 2396: http://www.ietf.org/rfc/rfc2396.txt 1770 1762 1771 The ``permalink`` decorator 1763 1772 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ django/branches/boulder-oracle-sprint/docs/syndication_feeds.txt
r5148 r5259 147 147 passing it a single parameter, ``item``, which is the object itself. 148 148 Both ``get_absolute_url()`` and ``item_link()`` should return the item's 149 URL as a normal Python string. 149 URL as a normal Python string. As with ``get_absolute_url()``, the 150 result of ``item_link()`` will be included directly in the URL, so you 151 are responsible for doing all necessary URL quoting and conversion to 152 ASCII inside the method itself. 150 153 151 154 * For the LatestEntries example above, we could have very simple feed templates:
