Ticket #14758: fix-queryset-headers-2.diff

File fix-queryset-headers-2.diff, 14.5 KB (added by Adam Vandenberg, 14 years ago)

Updated patch.

  • docs/ref/models/querysets.txt

    diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
    index ccea588..3faa696 100644
    a b described here.  
    119119QuerySet API
    120120============
    121121
    122 Though you usually won't create one manually -- you'll go through a :class:`Manager` -- here's the formal declaration of a ``QuerySet``:
     122Though you usually won't create one manually -- you'll go through a
     123:class:`Manager` -- here's the formal declaration of a ``QuerySet``:
    123124
    124125.. class:: QuerySet([model=None])
    125126
    126127Usually when you'll interact with a ``QuerySet`` you'll use it by :ref:`chaining
    127128filters <chaining-filters>`. To make this work, most ``QuerySet`` methods return new querysets.
    128129
    129 QuerySet methods that return new QuerySets
    130 ------------------------------------------
     130Methods that return new QuerySets
     131---------------------------------
    131132
    132133Django provides a range of ``QuerySet`` refinement methods that modify either
    133134the types of results returned by the ``QuerySet`` or the way its SQL query is
    134135executed.
    135136
    136 ``filter(**kwargs)``
    137 ~~~~~~~~~~~~~~~~~~~~
     137filter
     138~~~~~~
    138139
    139140.. method:: filter(**kwargs)
    140141
    The lookup parameters (``**kwargs``) should be in the format described in  
    145146`Field lookups`_ below. Multiple parameters are joined via ``AND`` in the
    146147underlying SQL statement.
    147148
    148 ``exclude(**kwargs)``
    149 ~~~~~~~~~~~~~~~~~~~~~
     149exclude
     150~~~~~~~
    150151
    151152.. method:: exclude(**kwargs)
    152153
    In SQL terms, that evaluates to::  
    180181
    181182Note the second example is more restrictive.
    182183
    183 ``annotate(*args, **kwargs)``
    184 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     184annotate
     185~~~~~~~~
    185186
    186187.. method:: annotate(*args, **kwargs)
    187188
    control the name of the annotation::  
    224225For an in-depth discussion of aggregation, see :doc:`the topic guide on
    225226Aggregation </topics/db/aggregation>`.
    226227
    227 ``order_by(*fields)``
    228 ~~~~~~~~~~~~~~~~~~~~~
     228order_by
     229~~~~~~~~
    229230
    230231.. method:: order_by(*fields)
    231232
    primary key if there is no ``Meta.ordering`` specified. For example::  
    267268...since the ``Blog`` model has no default ordering specified.
    268269
    269270Be cautious when ordering by fields in related models if you are also using
    270 ``distinct()``. See the note in the `distinct()`_ section for an explanation
    271 of how related model ordering can change the expected results.
     271``distinct()``. See the note in :meth:`distinct` for an explanation of how
     272related model ordering can change the expected results.
    272273
    273274It is permissible to specify a multi-valued field to order the results by (for
    274275example, a ``ManyToMany`` field). Normally this won't be a sensible thing to
    fields with care and make sure the results are what you expect.  
    280281
    281282.. versionadded:: 1.0
    282283
    283 If you don't want any ordering to be applied to a query, not even the default
    284 ordering, call ``order_by()`` with no parameters.
    285 
    286 .. versionadded:: 1.0
    287 
    288284The syntax for ordering across related models has changed. See the `Django 0.96
    289285documentation`_ for the old behaviour.
    290286
    There's no way to specify whether ordering should be case sensitive. With  
    294290respect to case-sensitivity, Django will order results however your database
    295291backend normally orders them.
    296292
     293If you don't want any ordering to be applied to a query, not even the default
     294ordering, call ``order_by()`` with no parameters.
     295
    297296.. versionadded:: 1.1
    298297
    299298You can tell if a query is ordered or not by checking the
    300299:attr:`QuerySet.ordered` attribute, which will be ``True`` if the
    301300``QuerySet`` has been ordered in any way.
    302301
    303 ``reverse()``
    304 ~~~~~~~~~~~~~
     302reverse
     303~~~~~~~
    305304
    306305.. method:: reverse()
    307306
    a model which defines a default ordering, or when using  
    330329ordering was undefined prior to calling ``reverse()``, and will remain
    331330undefined afterward).
    332331
    333 ``distinct()``
    334 ~~~~~~~~~~~~~~
     332distinct
     333~~~~~~~~
    335334
    336335.. method:: distinct()
    337336
    query spans multiple tables, it's possible to get duplicate results when a  
    345344``QuerySet`` is evaluated. That's when you'd use ``distinct()``.
    346345
    347346.. note::
    348     Any fields used in an `order_by(*fields)`_ call are included in the SQL
     347    Any fields used in an :meth:`order_by` call are included in the SQL
    349348    ``SELECT`` columns. This can sometimes lead to unexpected results when
    350349    used in conjunction with ``distinct()``. If you order by fields from a
    351350    related model, those fields will be added to the selected columns and they
    query spans multiple tables, it's possible to get duplicate results when a  
    363362    ``values()`` together, be careful when ordering by fields not in the
    364363    ``values()`` call.
    365364
    366 ``values(*fields)``
    367 ~~~~~~~~~~~~~~~~~~~
     365values
     366~~~~~~
    368367
    369368.. method:: values(*fields)
    370369
    A few subtleties that are worth mentioning:  
    419418
    420419        >>> Entry.objects.values('blog_id')
    421420        [{'blog_id': 1}, ...]
     421
    422422    * When using ``values()`` together with ``distinct()``, be aware that
    423       ordering can affect the results. See the note in the `distinct()`_
    424       section, above, for details.
     423      ordering can affect the results. See the note in :meth:`distinct` for
     424      details.
     425
    425426    * If you use a ``values()`` clause after an ``extra()`` clause,
    426427      any fields defined by a ``select`` argument in the ``extra()``
    427428      must be explicitly included in the ``values()`` clause. However,
    and ``ManyToManyField`` attributes::  
    472473   pronounced if you include multiple such fields in your ``values()`` query,
    473474   in which case all possible combinations will be returned.
    474475
    475 ``values_list(*fields)``
    476 ~~~~~~~~~~~~~~~~~~~~~~~~
     476values_list
     477~~~~~~~~~~~
    477478
    478479.. method:: values_list(*fields)
    479480
    It is an error to pass in ``flat`` when there is more than one field.  
    502503If you don't pass any values to ``values_list()``, it will return all the
    503504fields in the model, in the order they were declared.
    504505
    505 ``dates(field, kind, order='ASC')``
    506 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     506dates
     507~~~~~
    507508
    508509.. method:: dates(field, kind, order='ASC')
    509510
    Examples::  
    538539    >>> Entry.objects.filter(headline__contains='Lennon').dates('pub_date', 'day')
    539540    [datetime.datetime(2005, 3, 20)]
    540541
    541 ``none()``
    542 ~~~~~~~~~~
     542none
     543~~~~
    543544
    544545.. method:: none()
    545546
    Examples::  
    555556    >>> Entry.objects.none()
    556557    []
    557558
    558 ``all()``
    559 ~~~~~~~~~
     559all
     560~~~
    560561
    561562.. method:: all()
    562563
    563564.. versionadded:: 1.0
    564565
    565 Returns a ''copy'' of the current ``QuerySet`` (or ``QuerySet`` subclass you
     566Returns a *copy* of the current ``QuerySet`` (or ``QuerySet`` subclass you
    566567pass in). This can be useful in some situations where you might want to pass
    567568in either a model manager or a ``QuerySet`` and do further filtering on the
    568569result. You can safely call ``all()`` on either object and then you'll
    definitely have a ``QuerySet`` to work with.  
    570571
    571572.. _select-related:
    572573
    573 ``select_related()``
    574 ~~~~~~~~~~~~~~~~~~~~
     574select_related
     575~~~~~~~~~~~~~~
    575576
    576577.. method:: select_related()
    577578
    related object.  
    691692``OneToOneFields`` will not be traversed in the reverse direction if you
    692693are performing a depth-based ``select_related``.
    693694
    694 ``extra(select=None, where=None, params=None, tables=None, order_by=None, select_params=None)``
    695 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     695extra
     696~~~~~
    696697
    697698.. method:: extra(select=None, where=None, params=None, tables=None, order_by=None, select_params=None)
    698699
    of the arguments is required, but you should use at least one of them.  
    854855
    855856        Entry.objects.extra(where=['headline=%s'], params=['Lennon'])
    856857
    857 ``defer(*fields)``
    858 ~~~~~~~~~~~~~~~~~~
     858defer
     859~~~~~
    859860
    860861.. method:: defer(*fields)
    861862
    deferred set::  
    882883    # Defers both the body and headline fields.
    883884    Entry.objects.defer("body").filter(rating=5).defer("headline")
    884885
    885 The order in which fields are added to the deferred set does not matter. Calling ``defer()`` with a field name that has already been deferred is harmless (the field will still be deferred).
     886The order in which fields are added to the deferred set does not matter.
     887Calling ``defer()`` with a field name that has already been deferred is
     888harmless (the field will still be deferred).
    886889
    887890You can defer loading of fields in related models (if the related models are
    888891loading via ``select_related()``) by using the standard double-underscore
    eventually).  
    914917    bother using ``defer()``; leave it until your query construction has
    915918    settled down and you understand where the hot-points are.
    916919
    917 ``only(*fields)``
    918 ~~~~~~~~~~~~~~~~~
     920only
     921~~~~
    919922
    920923.. method:: only(*fields)
    921924
    logically::  
    952955    # existing set of fields).
    953956    Entry.objects.defer("body").only("headline", "body")
    954957
    955 ``using(alias)``
    956 ~~~~~~~~~~~~~~~~
     958using
     959~~~~~
    957960
    958961.. method:: using(alias)
    959962
    For example::  
    973976    >>> Entry.objects.using('backup')
    974977
    975978
    976 QuerySet methods that do not return QuerySets
    977 ---------------------------------------------
     979Methods that do not return QuerySets
     980------------------------------------
    978981
    979982The following ``QuerySet`` methods evaluate the ``QuerySet`` and return
    980983something *other than* a ``QuerySet``.
    something *other than* a ``QuerySet``.  
    982985These methods do not use a cache (see :ref:`caching-and-querysets`). Rather,
    983986they query the database each time they're called.
    984987
    985 ``get(**kwargs)``
    986 ~~~~~~~~~~~~~~~~~
     988get
     989~~~
    987990
    988991.. method:: get(**kwargs)
    989992
    The ``DoesNotExist`` exception inherits from  
    10111014    except ObjectDoesNotExist:
    10121015        print "Either the entry or blog doesn't exist."
    10131016
    1014 ``create(**kwargs)``
    1015 ~~~~~~~~~~~~~~~~~~~~
     1017create
     1018~~~~~~
    10161019
    10171020.. method:: create(**kwargs)
    10181021
    The :ref:`force_insert <ref-models-force-insert>` parameter is documented  
    10311034elsewhere, but all it means is that a new object will always be created.
    10321035Normally you won't need to worry about this. However, if your model contains a
    10331036manual primary key value that you set and if that value already exists in the
    1034 database, a call to ``create()`` will fail with an ``IntegrityError`` since
    1035 primary keys must be unique. So remember to be prepared to handle the
    1036 exception if you are using manual primary keys.
     1037database, a call to ``create()`` will fail with an :exc:`IntegrityError` since
     1038primary keys must be unique. So remember to be prepared to handle the exception
     1039if you are using manual primary keys.
    10371040
    1038 ``get_or_create(**kwargs)``
    1039 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     1041get_or_create
     1042~~~~~~~~~~~~~
    10401043
    10411044.. method:: get_or_create(**kwargs)
    10421045
    has a side effect on your data. For more, see `Safe methods`_ in the HTTP spec.  
    11051108
    11061109.. _Safe methods: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1
    11071110
    1108 ``count()``
    1109 ~~~~~~~~~~~
     1111count
     1112~~~~~
    11101113
    11111114.. method:: count()
    11121115
    Depending on which database you're using (e.g. PostgreSQL vs. MySQL),  
    11311134is an underlying implementation quirk that shouldn't pose any real-world
    11321135problems.
    11331136
    1134 ``in_bulk(id_list)``
    1135 ~~~~~~~~~~~~~~~~~~~~
     1137in_bulk
     1138~~~~~~~
    11361139
    11371140.. method:: in_bulk(id_list)
    11381141
    Example::  
    11501153
    11511154If you pass ``in_bulk()`` an empty list, you'll get an empty dictionary.
    11521155
    1153 ``iterator()``
    1154 ~~~~~~~~~~~~~~
     1156iterator
     1157~~~~~~~~
    11551158
    11561159.. method:: iterator()
    11571160
    been evaluated will force it to evaluate again, repeating the query.  
    11681171
    11691172.. _iterator: http://www.python.org/dev/peps/pep-0234/
    11701173
    1171 ``latest(field_name=None)``
    1172 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     1174latest
     1175~~~~~~
    11731176
    11741177.. method:: latest(field_name=None)
    11751178
    exist with the given parameters.  
    11901193
    11911194Note ``latest()`` exists purely for convenience and readability.
    11921195
    1193 ``aggregate(*args, **kwargs)``
    1194 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     1196aggregate
     1197~~~~~~~~~
    11951198
    11961199.. method:: aggregate(*args, **kwargs)
    11971200
    control the name of the aggregation value that is returned::  
    12241227For an in-depth discussion of aggregation, see :doc:`the topic guide on
    12251228Aggregation </topics/db/aggregation>`.
    12261229
    1227 ``exists()``
    1228 ~~~~~~~~~~~~
     1230exists
     1231~~~~~~
    12291232
    12301233.. method:: exists()
    12311234
    that it will be at some point, then using ``some_query_set.exists()`` will do  
    12401243more overall work (an additional query) than simply using
    12411244``bool(some_query_set)``.
    12421245
    1243 ``update(**kwargs)``
    1244 ~~~~~~~~~~~~~~~~~~~~
     1246update
     1247~~~~~~
    12451248
    12461249.. method:: update(**kwargs)
    12471250
    The ``update()`` method does a bulk update and does not call any ``save()``  
    12651268methods on your models, nor does it emit the ``pre_save`` or ``post_save``
    12661269signals (which are a consequence of calling ``save()``).
    12671270
    1268 ``delete()``
    1269 ~~~~~~~~~~~~~~~~~~~~
     1271delete
     1272~~~~~~
    12701273
    12711274.. method:: delete()
    12721275
    SQL equivalent::  
    17361739
    17371740Note this is only available in MySQL and requires direct manipulation of the
    17381741database to add the full-text index. By default Django uses BOOLEAN MODE for
    1739 full text searches. `Please check MySQL documentation for additional details. <http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html>`_
     1742full text searches. `See the MySQL documentation for additional details.
     1743<http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html>`_
    17401744
    17411745
    17421746.. fieldlookup:: regex
    Django provides the following aggregation functions in the  
    18051809aggregate functions, see
    18061810:doc:`the topic guide on aggregation </topics/db/aggregation>`.
    18071811
    1808 ``Avg``
    1809 ~~~~~~~
     1812Avg
     1813~~~
    18101814
    18111815.. class:: Avg(field)
    18121816
    Returns the mean value of the given field.  
    18151819    * Default alias: ``<field>__avg``
    18161820    * Return type: float
    18171821
    1818 ``Count``
    1819 ~~~~~~~~~
     1822Count
     1823~~~~~
    18201824
    18211825.. class:: Count(field, distinct=False)
    18221826
    Has one optional argument:  
    18321836    If distinct=True, the count will only include unique instances. This has
    18331837    the SQL equivalent of ``COUNT(DISTINCT field)``. Default value is ``False``.
    18341838
    1835 ``Max``
    1836 ~~~~~~~
     1839Max
     1840~~~
    18371841
    18381842.. class:: Max(field)
    18391843
    Returns the maximum value of the given field.  
    18421846    * Default alias: ``<field>__max``
    18431847    * Return type: same as input field
    18441848
    1845 ``Min``
    1846 ~~~~~~~
     1849Min
     1850~~~
    18471851
    18481852.. class:: Min(field)
    18491853
    Returns the minimum value of the given field.  
    18521856    * Default alias: ``<field>__min``
    18531857    * Return type: same as input field
    18541858
    1855 ``StdDev``
    1856 ~~~~~~~~~~
     1859StdDev
     1860~~~~~~
    18571861
    18581862.. class:: StdDev(field, sample=False)
    18591863
    Has one optional argument:  
    18751879    available as an extension module for SQLite. Consult the SQlite
    18761880    documentation for instructions on obtaining and installing this extension.
    18771881
    1878 ``Sum``
    1879 ~~~~~~~
     1882Sum
     1883~~~
    18801884
    18811885.. class:: Sum(field)
    18821886
    Computes the sum of all values of the given field.  
    18851889    * Default alias: ``<field>__sum``
    18861890    * Return type: same as input field
    18871891
    1888 ``Variance``
    1889 ~~~~~~~~~~~~
     1892Variance
     1893~~~~~~~~
    18901894
    18911895.. class:: Variance(field, sample=False)
    18921896
Back to Top