Ticket #1742: db-api.patch
File db-api.patch, 3.3 KB (added by , 19 years ago) |
---|
-
docs/db-api.txt
216 216 lookup parameters. 217 217 218 218 The lookup parameters (``**kwargs`` in the above function definitions) should 219 be in the format described in _`Field lookups`below.219 be in the format described in `Field lookups`_ below. 220 220 221 221 For example, to get a ``QuerySet`` of blog entries from the year 2006, use 222 222 ``filter()`` like so:: … … 298 298 * **len().** A ``QuerySet`` is evaluated when you call ``len()`` on it. 299 299 This, as you might expect, returns the length of the result list. 300 300 301 Note: *Don't* use ``len()`` on ``QuerySet``sif all you want to do is301 Note: *Don't* use ``len()`` on a ``QuerySet`` if all you want to do is 302 302 determine the number of records in the set. It's much more efficient to 303 303 handle a count at the database level, using SQL's ``SELECT COUNT(*)``, 304 304 and Django provides a ``count()`` method for precisely this reason. See … … 328 328 parameters. 329 329 330 330 The lookup parameters (``**kwargs``) should be in the format described in 331 _`Field lookups`below. Multiple parameters are joined via ``AND`` in the331 `Field lookups`_ below. Multiple parameters are joined via ``AND`` in the 332 332 underlying SQL statement. 333 333 334 334 ``exclude(**kwargs)`` … … 338 338 lookup parameters. 339 339 340 340 The lookup parameters (``**kwargs``) should be in the format described in 341 _`Field lookups`below. Multiple parameters are joined via ``AND`` in the341 `Field lookups`_ below. Multiple parameters are joined via ``AND`` in the 342 342 underlying SQL statement, and the whole thing is enclosed in a ``NOT()``. 343 343 344 344 This example excludes all entries whose ``pub_date`` is the current date/time … … 650 650 ~~~~~~~~~~~~~~~~~ 651 651 652 652 Returns the object matching the given lookup parameters, which should be in 653 the format described in _`Field lookups`.653 the format described in `Field lookups`_. 654 654 655 655 ``get()`` raises ``AssertionError`` if more than one object was found. 656 656 … … 1070 1070 ``QuerySet`` reuse the cached results. 1071 1071 1072 1072 Keep this caching behavior in mind, because it may bite you if you don't use 1073 your ``QuerySet`` s correctly. For example, the following will create two1074 ``QuerySet`` s, evaluate them, and throw them away::1073 your ``QuerySet`` objects correctly. For example, the following will create two 1074 ``QuerySet`` objects, evaluate them, and throw them away:: 1075 1075 1076 1076 print [e.headline for e in Entry.objects.all()] 1077 1077 print [e.pub_date for e in Entry.objects.all()] … … 1349 1349 >>> c = Choice(poll_id=p.id, choice="Over easy", votes=0) 1350 1350 >>> c.save() 1351 1351 1352 Note that when using the ` create()`` method, you do not give any value1352 Note that when using the ``create()`` method, you do not give any value 1353 1353 for the ``id`` field, nor do you give a value for the field that stores 1354 1354 the relation (``poll_id`` in this case). 1355 1355 … … 1420 1420 ``DoesNotExist`` exception when appropriate. 1421 1421 1422 1422 Both methods accept optional keyword arguments, which should be in the format 1423 described in _`Field lookups`above.1423 described in `Field lookups`_ above. 1424 1424 1425 1425 Note that in the case of identical date values, these methods will use the ID 1426 1426 as a fallback check. This guarantees that no records are skipped or duplicated.