Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:15:33 (5 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis

    • Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
  • django/branches/gis/docs/db-api.txt

    r7918 r8215  
    464464``extra()`` calls, Django will not inspect these fragments to see if they need 
    465465to be rewritten because of changes in the merged query. So test the effects 
    466 carefully. Also realise that if you are combining two ``QuerySets`` with 
     466carefully. Also realize that if you are combining two ``QuerySets`` with 
    467467``|``, you cannot use ``extra(select=...)`` or ``extra(where=...)`` on *both* 
    468468``QuerySets``. You can only use those calls on one or the other (Django will 
     
    16771677    Blog.objects.filter(entry__headline__contains='Lennon') 
    16781678 
     1679If you are filtering across multiple relationships and one of the intermediate 
     1680models doesn't have a value that meets the filter condition, Django will treat 
     1681it as if there is an empty (all values are ``NULL``), but valid, object there. 
     1682All this means is that no error will be raised. For example, in this filter:: 
     1683 
     1684    Blog.objects.filter(entry__author__name='Lennon') 
     1685 
     1686(if there was a related ``Author`` model), if there was no ``author`` 
     1687associated with an entry, it would be treated as if there was also no ``name`` 
     1688attached, rather than raising an error because of the missing ``author``. 
     1689Usually this is exactly what you want to have happen. The only case where it 
     1690might be confusing is if you are using ``isnull``. Thus:: 
     1691 
     1692    Blog.objects.filter(entry__author__name__isnull=True) 
     1693 
     1694will return ``Blog`` objects that have an empty ``name`` on the ``author`` and 
     1695also those which have an empty ``author`` on the ``entry``. If you don't want 
     1696those latter objects, you could write:: 
     1697 
     1698    Blog.objetcs.filter(entry__author__isnull=False, 
     1699            entry__author__name__isnull=True) 
     1700 
    16791701Spanning multi-valued relationships 
    16801702~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    22192241every item in a ``QuerySet`` and make sure that the ``save()`` method is 
    22202242called on each instance, you don't need any special function to handle that. 
    2221 Just loop over them and call ``save()``: 
     2243Just loop over them and call ``save()``:: 
    22222244 
    22232245    for item in my_queryset: 
     
    22812303to the file, according to your ``MEDIA_ROOT`` setting. 
    22822304 
     2305.. note:: 
     2306    It is only valid to call this method **after** saving the model when the 
     2307    field has been set. Prior to saving, the value returned will not contain 
     2308    the upload directory (the `upload_to` parameter) in the path. 
     2309 
    22832310Note that ``ImageField`` is technically a subclass of ``FileField``, so every 
    22842311model with an ``ImageField`` will also get this method. 
     
    22912318according to your ``MEDIA_URL`` setting. If the value is blank, this method 
    22922319returns an empty string. 
     2320 
     2321.. note:: 
     2322    As with ``get_FOO_filename()``, it is only valid to call this method 
     2323    **after** saving the model, otherwise an incorrect result will be 
     2324    returned. 
    22932325 
    22942326get_FOO_size()