1.5.txt 7.9 KB

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