1.5.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ============================================
  2. Django 1.5 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. These release notes cover the `new features`_, as well
  5. as some `backwards incompatible changes`_ you'll want to be aware of
  6. when upgrading from Django 1.4 or older versions. We've also dropped some
  7. features, which are detailed in :doc:`our deprecation plan
  8. </internals/deprecation>`, and we've `begun the deprecation process for some
  9. features`_.
  10. .. _`new features`: `What's new in Django 1.5`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.5`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.5`_
  13. Python compatibility
  14. ====================
  15. Django 1.5 has dropped support for Python 2.5. Python 2.6 is now the minimum
  16. required Python version. Django is tested and supported on Python 2.6 and
  17. 2.7.
  18. This change should affect only a small number of Django users, as most
  19. operating-system vendors today are shipping Python 2.6 or newer as their default
  20. version. If you're still using Python 2.5, however, you'll need to stick to
  21. Django 1.4 until you can upgrade your Python version. Per :doc:`our support policy
  22. </internals/release-process>`, Django 1.4 will continue to receive security
  23. support until the release of Django 1.6.
  24. Django 1.5 does not run on Jython, because Jython doesn't currently offer any
  25. version compatible with Python 2.6.
  26. What's new in Django 1.5
  27. ========================
  28. Support for saving a subset of model's fields
  29. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30. The method :meth:`Model.save() <django.db.models.Model.save()>` has a new
  31. keyword argument ``update_fields``. By using this argument it is possible to
  32. save only a select list of model's fields. This can be useful for performance
  33. reasons or when trying to avoid overwriting concurrent changes.
  34. See the :meth:`Model.save() <django.db.models.Model.save()>` documentation for
  35. more details.
  36. Caching of related model instances
  37. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38. When traversing relations, the ORM will avoid re-fetching objects that were
  39. previously loaded. For example, with the tutorial's models::
  40. >>> first_poll = Poll.objects.all()[0]
  41. >>> first_choice = first_poll.choice_set.all()[0]
  42. >>> first_choice.poll is first_poll
  43. True
  44. In Django 1.5, the third line no longer triggers a new SQL query to fetch
  45. ``first_choice.poll``; it was set by the second line.
  46. For one-to-one relationships, both sides can be cached. For many-to-one
  47. relationships, only the single side of the relationship can be cached. This
  48. is particularly helpful in combination with ``prefetch_related``.
  49. ``{% verbatim %}`` template tag
  50. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. To make it easier to deal with javascript templates which collide with Django's
  52. syntax, you can now use the :ttag:`verbatim` block tag to avoid parsing the
  53. tag's content.
  54. Retreival of ``ContentType`` instances associated with proxy models
  55. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. The methods :meth:`ContentTypeManager.get_for_model() <django.contrib.contenttypes.models.ContentTypeManager.get_for_model()>`
  57. and :meth:`ContentTypeManager.get_for_models() <django.contrib.contenttypes.models.ContentTypeManager.get_for_models()>`
  58. have a new keyword argument – respectively ``for_concrete_model`` and ``for_concrete_models``.
  59. By passing ``False`` using this argument it is now possible to retreive the
  60. :class:`ContentType <django.contrib.contenttypes.models.ContentType>`
  61. associated with proxy models.
  62. Minor features
  63. ~~~~~~~~~~~~~~
  64. Django 1.5 also includes several smaller improvements worth noting:
  65. * The template engine now interprets ``True``, ``False`` and ``None`` as the
  66. corresponding Python objects.
  67. * :mod:`django.utils.timezone` provides a helper for converting aware
  68. datetimes between time zones. See :func:`~django.utils.timezone.localtime`.
  69. * The generic views support OPTIONS requests.
  70. * Management commands do not raise ``SystemExit`` any more when called by code
  71. from :ref:`call_command <call-command>`. Any exception raised by the command
  72. (mostly :ref:`CommandError <ref-command-exceptions>`) is propagated.
  73. * The dumpdata management command outputs one row at a time, preventing
  74. out-of-memory errors when dumping large datasets.
  75. * In the localflavor for Canada, "pq" was added to the acceptable codes for
  76. Quebec. It's an old abbreviation.
  77. Backwards incompatible changes in 1.5
  78. =====================================
  79. .. warning::
  80. In addition to the changes outlined in this section, be sure to review the
  81. :doc:`deprecation plan </internals/deprecation>` for any features that
  82. have been removed. If you haven't updated your code within the
  83. deprecation timeline for a given feature, its removal may appear as a
  84. backwards incompatible change.
  85. Context in year archive class-based views
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. For consistency with the other date-based generic views,
  88. :class:`~django.views.generic.dates.YearArchiveView` now passes ``year`` in
  89. the context as a :class:`datetime.date` rather than a string. If you are
  90. using ``{{ year }}`` in your templates, you must replace it with ``{{
  91. year|date:"Y" }}``.
  92. ``next_year`` and ``previous_year`` were also added in the context. They are
  93. calculated according to ``allow_empty`` and ``allow_future``.
  94. OPTIONS, PUT and DELETE requests in the test client
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. Unlike GET and POST, these HTTP methods aren't implemented by web browsers.
  97. Rather, they're used in APIs, which transfer data in various formats such as
  98. JSON or XML. Since such requests may contain arbitrary data, Django doesn't
  99. attempt to decode their body.
  100. However, the test client used to build a query string for OPTIONS and DELETE
  101. requests like for GET, and a request body for PUT requests like for POST. This
  102. encoding was arbitrary and inconsistent with Django's behavior when it
  103. receives the requests, so it was removed in Django 1.5.
  104. If you were using the ``data`` parameter in an OPTIONS or a DELETE request,
  105. you must convert it to a query string and append it to the ``path`` parameter.
  106. If you were using the ``data`` parameter in a PUT request without a
  107. ``content_type``, you must encode your data before passing it to the test
  108. client and set the ``content_type`` argument.
  109. String types of hasher method parameters
  110. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. If you have written a :ref:`custom password hasher <auth_password_storage>`,
  112. your ``encode()``, ``verify()`` or ``safe_summary()`` methods should accept
  113. Unicode parameters (``password``, ``salt`` or ``encoded``). If any of the
  114. hashing methods need byte strings, you can use the
  115. :func:`~django.utils.encoding.smart_str` utility to encode the strings.
  116. Validation of previous_page_number and next_page_number
  117. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118. When using :doc:`object pagination </topics/pagination>`,
  119. the ``previous_page_number()`` and ``next_page_number()`` methods of the
  120. :class:`~django.core.paginator.Page` object did not check if the returned
  121. number was inside the existing page range.
  122. It does check it now and raises an :exc:`InvalidPage` exception when the number
  123. is either too low or too high.
  124. Features deprecated in 1.5
  125. ==========================
  126. ``django.utils.simplejson``
  127. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128. Since Django 1.5 drops support for Python 2.5, we can now rely on the
  129. :mod:`json` module being in Python's standard library -- so we've removed
  130. our own copy of ``simplejson``. You can safely change any use of
  131. :mod:`django.utils.simplejson` to :mod:`json`.
  132. ``itercompat.product``
  133. ~~~~~~~~~~~~~~~~~~~~~~
  134. The :func:`~django.utils.itercompat.product` function has been deprecated. Use
  135. the built-in :func:`itertools.product` instead.