Fixed #26526 -- Documented QuerySet.latest()'s dependency on database ordering.

This commit is contained in:
Chad Shryock 2016-06-02 10:52:58 -07:00 committed by Tim Graham
parent c7b1b81352
commit e6c5e68acd
1 changed files with 11 additions and 0 deletions

View File

@ -1952,6 +1952,17 @@ given parameters.
Note that ``earliest()`` and ``latest()`` exist purely for convenience and Note that ``earliest()`` and ``latest()`` exist purely for convenience and
readability. readability.
.. admonition:: ``earliest()`` and ``latest()`` may return instances with null dates.
Since ordering is delegated to the database, results on fields that allow
null values may be ordered differently if you use different databases. For
example, PostgreSQL and MySQL sort null values as if they are higher than
non-null values, while SQLite does the opposite.
You may want to filter out null values::
Entry.objects.filter(pub_date__isnull=False).latest('pub_date')
``earliest()`` ``earliest()``
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~