1.6.txt 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. ============================================
  2. Django 1.6 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. .. note::
  5. Dedicated to Malcolm Tredinnick
  6. On March 17, 2013, the Django project and the free software community lost
  7. a very dear friend and developer.
  8. Malcolm was a long-time contributor to Django, a model community member, a
  9. brilliant mind, and a friend. His contributions to Django — and to many other
  10. open source projects — are nearly impossible to enumerate. Many on the core
  11. Django team had their first patches reviewed by him; his mentorship enriched
  12. us. His consideration, patience, and dedication will always be an inspiration
  13. to us.
  14. This release of Django is for Malcolm.
  15. -- The Django Developers
  16. Welcome to Django 1.6!
  17. These release notes cover the `new features`_, as well as some `backwards
  18. incompatible changes`_ you'll want to be aware of when upgrading from Django
  19. 1.5 or older versions. We've also dropped some features, which are detailed in
  20. :doc:`our deprecation plan </internals/deprecation>`, and we've `begun the
  21. deprecation process for some features`_.
  22. .. _`new features`: `What's new in Django 1.6`_
  23. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.6`_
  24. .. _`begun the deprecation process for some features`: `Features deprecated in 1.6`_
  25. What's new in Django 1.6
  26. ========================
  27. Simplified default project and app templates
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. The default templates used by :djadmin:`startproject` and :djadmin:`startapp`
  30. have been simplified and modernized. The :doc:`admin
  31. </ref/contrib/admin/index>` is now enabled by default in new projects; the
  32. :doc:`sites </ref/contrib/sites>` framework no longer is. :ref:`Language
  33. detection <how-django-discovers-language-preference>` and :ref:`clickjacking
  34. prevention <clickjacking-prevention>` are turned on.
  35. If the default templates don't suit your tastes, you can use :ref:`custom
  36. project and app templates <custom-app-and-project-templates>`.
  37. Improved transaction management
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. Django's transaction management was overhauled. Database-level autocommit is
  40. now turned on by default. This makes transaction handling more explicit and
  41. should improve performance. The existing APIs were deprecated, and new APIs
  42. were introduced, as described in the :doc:`transaction management docs
  43. </topics/db/transactions>`.
  44. Please review carefully the list of :ref:`known backwards-incompatibilities
  45. <transactions-upgrading-from-1.5>` to determine if you need to make changes in
  46. your code.
  47. Persistent database connections
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. Django now supports reusing the same database connection for several requests.
  50. This avoids the overhead of re-establishing a connection at the beginning of
  51. each request. For backwards compatibility, this feature is disabled by
  52. default. See :ref:`persistent-database-connections` for details.
  53. Discovery of tests in any test module
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. Django 1.6 ships with a new test runner that allows more flexibility in the
  56. location of tests. The previous runner
  57. (``django.test.simple.DjangoTestSuiteRunner``) found tests only in the
  58. ``models.py`` and ``tests.py`` modules of a Python package in
  59. :setting:`INSTALLED_APPS`.
  60. The new runner (``django.test.runner.DiscoverRunner``) uses the test discovery
  61. features built into ``unittest2`` (the version of ``unittest`` in the
  62. Python 2.7+ standard library, and bundled with Django). With test discovery,
  63. tests can be located in any module whose name matches the pattern ``test*.py``.
  64. In addition, the test labels provided to ``./manage.py test`` to nominate
  65. specific tests to run must now be full Python dotted paths (or directory
  66. paths), rather than ``applabel.TestCase.test_method_name`` pseudo-paths. This
  67. allows running tests located anywhere in your codebase, rather than only in
  68. :setting:`INSTALLED_APPS`. For more details, see :doc:`/topics/testing/index`.
  69. This change is backwards-incompatible; see the :ref:`backwards-incompatibility
  70. notes<new-test-runner>`.
  71. Time zone aware aggregation
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. The support for :doc:`time zones </topics/i18n/timezones>` introduced in
  74. Django 1.4 didn't work well with :meth:`QuerySet.dates()
  75. <django.db.models.query.QuerySet.dates>`: aggregation was always performed in
  76. UTC. This limitation was lifted in Django 1.6. Use :meth:`QuerySet.datetimes()
  77. <django.db.models.query.QuerySet.datetimes>` to perform time zone aware
  78. aggregation on a :class:`~django.db.models.DateTimeField`.
  79. Support for savepoints in SQLite
  80. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. Django 1.6 adds support for savepoints in SQLite, with some :ref:`limitations
  82. <savepoints-in-sqlite>`.
  83. ``BinaryField`` model field
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. A new :class:`django.db.models.BinaryField` model field allows storage of raw
  86. binary data in the database.
  87. GeoDjango form widgets
  88. ~~~~~~~~~~~~~~~~~~~~~~
  89. GeoDjango now provides :ref:`form fields and widgets <ref-gis-forms-api>` for
  90. its geo-specialized fields. They are OpenLayers-based by default, but they can
  91. be customized to use any other JS framework.
  92. ``check`` management command added for verifying compatibility
  93. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. A ``check`` management command was added, enabling you to verify if your
  95. current configuration (currently oriented at settings) is compatible with the
  96. current version of Django.
  97. Minor features
  98. ~~~~~~~~~~~~~~
  99. * Authentication backends can raise ``PermissionDenied`` to immediately fail
  100. the authentication chain.
  101. * The ``HttpOnly`` flag can be set on the CSRF cookie with
  102. :setting:`CSRF_COOKIE_HTTPONLY`.
  103. * The :meth:`~django.test.TransactionTestCase.assertQuerysetEqual` now checks
  104. for undefined order and raises :exc:`~exceptions.ValueError` if undefined
  105. order is spotted. The order is seen as undefined if the given ``QuerySet``
  106. isn't ordered and there are more than one ordered values to compare against.
  107. * Added :meth:`~django.db.models.query.QuerySet.earliest` for symmetry with
  108. :meth:`~django.db.models.query.QuerySet.latest`.
  109. * In addition to :lookup:`year`, :lookup:`month` and :lookup:`day`, the ORM
  110. now supports :lookup:`hour`, :lookup:`minute` and :lookup:`second` lookups.
  111. * Django now wraps all PEP-249 exceptions.
  112. * The default widgets for :class:`~django.forms.EmailField`,
  113. :class:`~django.forms.URLField`, :class:`~django.forms.IntegerField`,
  114. :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` use
  115. the new type attributes available in HTML5 (``type='email'``, ``type='url'``,
  116. ``type='number'``). Note that due to erratic support of the ``number``
  117. input type with localized numbers in current browsers, Django only uses it
  118. when numeric fields are not localized.
  119. * The ``number`` argument for :ref:`lazy plural translations
  120. <lazy-plural-translations>` can be provided at translation time rather than
  121. at definition time.
  122. * For custom management commands: Verification of the presence of valid
  123. settings in commands that ask for it by using the
  124. :attr:`~django.core.management.BaseCommand.can_import_settings` internal
  125. option is now performed independently from handling of the locale that
  126. should be active during the execution of the command. The latter can now be
  127. influenced by the new
  128. :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal
  129. option. See :ref:`management-commands-and-locales` for more details.
  130. * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of
  131. :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with
  132. its ``object``\'s ``__dict__``.
  133. * :class:`~django.http.HttpResponseRedirect` and
  134. :class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
  135. attribute (equivalent to the URL the response will redirect to).
  136. * The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
  137. protocol available.
  138. * Added :class:`~django.contrib.messages.views.SuccessMessageMixin` which
  139. provides a ``success_message`` attribute for
  140. :class:`~django.views.generic.edit.FormView` based classes.
  141. * Added the :attr:`django.db.models.ForeignKey.db_constraint` and
  142. :attr:`django.db.models.ManyToManyField.db_constraint` options.
  143. * The jQuery library embedded in the admin has been upgraded to version 1.9.1.
  144. * Syndication feeds (:mod:`django.contrib.syndication`) can now pass extra
  145. context through to feed templates using a new
  146. :meth:`Feed.get_context_data()
  147. <django.contrib.syndication.Feed.get_context_data>` callback.
  148. * The admin list columns have a ``column-<field_name>`` class in the HTML
  149. so the columns header can be styled with CSS, e.g. to set a column width.
  150. * The :ref:`isolation level<database-isolation-level>` can be customized under
  151. PostgreSQL.
  152. * The :ttag:`blocktrans` template tag now respects
  153. :setting:`TEMPLATE_STRING_IF_INVALID` for variables not present in the
  154. context, just like other template constructs.
  155. * ``SimpleLazyObject``\s will now present more helpful representations in shell
  156. debugging situations.
  157. * Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
  158. with the OpenLayers widget in the admin.
  159. * The :meth:`Model.save() <django.db.models.Model.save()>` will do
  160. ``UPDATE`` - if not updated - ``INSERT`` instead of ``SELECT`` - if not
  161. found ``INSERT`` else ``UPDATE`` in case the model's primary key is set.
  162. * The documentation contains a :doc:`deployment checklist
  163. </howto/deployment/checklist>`.
  164. * The :djadmin:`diffsettings` command gained a ``--all`` option.
  165. * ``django.forms.fields.Field.__init__`` now calls ``super()``, allowing
  166. field mixins to implement ``__init__()`` methods that will reliably be
  167. called.
  168. * The ``validate_max`` parameter was added to ``BaseFormSet`` and
  169. :func:`~django.forms.formsets.formset_factory`, and ``ModelForm`` and inline
  170. versions of the same. The behavior of validation for formsets with
  171. ``max_num`` was clarified. The previously undocumented behavior that
  172. hardened formsets against memory exhaustion attacks was documented,
  173. and the undocumented limit of the higher of 1000 or ``max_num`` forms
  174. was changed so it is always 1000 more than ``max_num``.
  175. * Added ``BCryptSHA256PasswordHasher`` to resolve the password truncation issue
  176. with bcrypt.
  177. * `Pillow`_ is now the preferred image manipulation library to use with Django.
  178. `PIL`_ is pending deprecation (support to be removed in Django 1.8).
  179. To upgrade, you should **first** uninstall PIL, **then** install Pillow.
  180. .. _`Pillow`: https://pypi.python.org/pypi/Pillow
  181. .. _`PIL`: https://pypi.python.org/pypi/PIL
  182. * :class:`~django.forms.ModelForm` accepts several new ``Meta``
  183. options.
  184. * Fields included in the ``localized_fields`` list will be localized
  185. (by setting ``localize`` on the form field).
  186. * The ``labels``, ``help_texts`` and ``error_messages`` options may be used
  187. to customize the default fields, see
  188. :ref:`modelforms-overriding-default-fields` for details.
  189. * The ``choices`` argument to model fields now accepts an iterable of iterables
  190. instead of requiring an iterable of lists or tuples.
  191. * The reason phrase can be customized in HTTP responses using
  192. :attr:`~django.http.HttpResponse.reason_phrase`.
  193. * When giving the URL of the next page for
  194. :func:`~django.contrib.auth.views.logout`,
  195. :func:`~django.contrib.auth.views.password_reset`,
  196. :func:`~django.contrib.auth.views.password_reset_confirm`,
  197. and :func:`~django.contrib.auth.views.password_change`, you can now pass
  198. URL names and they will be resolved.
  199. * The :djadmin:`dumpdata` ``manage.py`` command now has a :djadminopt:`--pks`
  200. option which will allow users to specify the primary keys of objects they
  201. want to dump. This option can only be used with one model.
  202. * Added ``QuerySet`` methods :meth:`~django.db.models.query.QuerySet.first`
  203. and :meth:`~django.db.models.query.QuerySet.last` which are convenience
  204. methods returning the first or last object matching the filters. Returns
  205. ``None`` if there are no objects matching.
  206. * :class:`~django.views.generic.base.View` and
  207. :class:`~django.views.generic.base.RedirectView` now support HTTP ``PATCH``
  208. method.
  209. * :class:`GenericForeignKey <django.contrib.contenttypes.generic.GenericForeignKey>`
  210. now takes an optional
  211. :attr:`~django.contrib.contenttypes.generic.GenericForeignKey.for_concrete_model`
  212. argument, which when set to ``False`` allows the field to reference proxy
  213. models. The default is ``True`` to retain the old behavior.
  214. * The :class:`~django.middleware.locale.LocaleMiddleware` now stores the active
  215. language in session if it is not present there. This prevents loss of
  216. language settings after session flush, e.g. logout.
  217. * :exc:`~django.core.exceptions.SuspiciousOperation` has been differentiated
  218. into a number of subclasses, and each will log to a matching named logger
  219. under the ``django.security`` logging hierarchy. Along with this change,
  220. a ``handler400`` mechanism and default view are used whenever
  221. a ``SuspiciousOperation`` reaches the WSGI handler to return an
  222. ``HttpResponseBadRequest``.
  223. * The :exc:`~django.core.exceptions.DoesNotExist` exception now includes a
  224. message indicating the name of the attribute used for the lookup.
  225. * The :meth:`~django.db.models.query.QuerySet.get_or_create` method no longer
  226. requires at least one keyword argument.
  227. * The :class:`~django.test.SimpleTestCase` class includes a new assertion
  228. helper for testing formset errors:
  229. :meth:`~django.test.SimpleTestCase.assertFormsetError`.
  230. * The list of related fields added to a
  231. :class:`~django.db.models.query.QuerySet` by
  232. :meth:`~django.db.models.query.QuerySet.select_related` can be cleared using
  233. ``select_related(None)``.
  234. * The :meth:`~django.contrib.admin.InlineModelAdmin.get_extra` and
  235. :meth:`~django.contrib.admin.InlineModelAdmin.get_max_num` methods on
  236. :class:`~django.contrib.admin.InlineModelAdmin` may be overridden to
  237. customize the extra and maximum number of inline forms.
  238. * Formsets now have a
  239. :meth:`~django.forms.formsets.BaseFormSet.total_error_count` method.
  240. * :class:`~django.forms.ModelForm` fields can now override error messages
  241. defined in model fields by using the
  242. :attr:`~django.forms.Field.error_messages` argument of a ``Field``'s
  243. constructor. To take advantage of this new feature with your custom fields,
  244. :ref:`see the updated recommendation <raising-validation-error>` for raising
  245. a ``ValidationError``.
  246. * :class:`~django.contrib.admin.ModelAdmin` now preserves filters on the list view
  247. after creating, editing or deleting an object. It's possible to restore the previous
  248. behavior of clearing filters by setting the
  249. :attr:`~django.contrib.admin.ModelAdmin.preserve_filters` attribute to ``False``.
  250. * Added
  251. :meth:`FormMixin.get_prefix<django.views.generic.edit.FormMixin.get_prefix>`
  252. (which returns
  253. :attr:`FormMixin.prefix<django.views.generic.edit.FormMixin.prefix>` by
  254. default) to allow customizing the :attr:`~django.forms.Form.prefix` of the
  255. form.
  256. Backwards incompatible changes in 1.6
  257. =====================================
  258. .. warning::
  259. In addition to the changes outlined in this section, be sure to review the
  260. :doc:`deprecation plan </internals/deprecation>` for any features that
  261. have been removed. If you haven't updated your code within the
  262. deprecation timeline for a given feature, its removal may appear as a
  263. backwards incompatible change.
  264. New transaction management model
  265. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  266. Behavior changes
  267. ^^^^^^^^^^^^^^^^
  268. Database-level autocommit is enabled by default in Django 1.6. While this
  269. doesn't change the general spirit of Django's transaction management, there
  270. are a few known backwards-incompatibilities, described in the :ref:`transaction
  271. management docs <transactions-upgrading-from-1.5>`. You should review your
  272. code to determine if you're affected.
  273. Savepoints and ``assertNumQueries``
  274. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  275. The changes in transaction management may result in additional statements to
  276. create, release or rollback savepoints. This is more likely to happen with
  277. SQLite, since it didn't support savepoints until this release.
  278. If tests using :meth:`~django.test.TransactionTestCase.assertNumQueries` fail
  279. because of a higher number of queries than expected, check that the extra
  280. queries are related to savepoints, and adjust the expected number of queries
  281. accordingly.
  282. Autocommit option for PostgreSQL
  283. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  284. In previous versions, database-level autocommit was only an option for
  285. PostgreSQL, and it was disabled by default. This option is now :ref:`ignored
  286. <postgresql-autocommit-mode>` and can be removed.
  287. .. _new-test-runner:
  288. New test runner
  289. ~~~~~~~~~~~~~~~
  290. In order to maintain greater consistency with Python's unittest module, the new
  291. test runner (``django.test.runner.DiscoverRunner``) does not automatically
  292. support some types of tests that were supported by the previous runner:
  293. * Tests in ``models.py`` and ``tests/__init__.py`` files will no longer be
  294. found and run. Move them to a file whose name begins with ``test``.
  295. * Doctests will no longer be automatically discovered. To integrate doctests in
  296. your test suite, follow the `recommendations in the Python documentation`_.
  297. Django bundles a modified version of the :mod:`doctest` module from the Python
  298. standard library (in ``django.test._doctest``) and includes some additional
  299. doctest utilities. These utilities are deprecated and will be removed in Django
  300. 1.8; doctest suites should be updated to work with the standard library's
  301. doctest module (or converted to unittest-compatible tests).
  302. If you wish to delay updates to your test suite, you can set your
  303. :setting:`TEST_RUNNER` setting to ``django.test.simple.DjangoTestSuiteRunner``
  304. to fully restore the old test behavior. ``DjangoTestSuiteRunner`` is deprecated
  305. but will not be removed from Django until version 1.8.
  306. .. _recommendations in the Python documentation: http://docs.python.org/2/library/doctest.html#unittest-api
  307. Addition of ``QuerySet.datetimes()``
  308. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  309. When the :doc:`time zone support </topics/i18n/timezones>` added in Django 1.4
  310. was active, :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>`
  311. lookups returned unexpected results, because the aggregation was performed in
  312. UTC. To fix this, Django 1.6 introduces a new API, :meth:`QuerySet.datetimes()
  313. <django.db.models.query.QuerySet.datetimes>`. This requires a few changes in
  314. your code.
  315. ``QuerySet.dates()`` returns ``date`` objects
  316. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  317. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` now returns a
  318. list of :class:`~datetime.date`. It used to return a list of
  319. :class:`~datetime.datetime`.
  320. :meth:`QuerySet.datetimes() <django.db.models.query.QuerySet.datetimes>`
  321. returns a list of :class:`~datetime.datetime`.
  322. ``QuerySet.dates()`` no longer usable on ``DateTimeField``
  323. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  324. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` raises an
  325. error if it's used on :class:`~django.db.models.DateTimeField` when time
  326. zone support is active. Use :meth:`QuerySet.datetimes()
  327. <django.db.models.query.QuerySet.datetimes>` instead.
  328. ``date_hierarchy`` requires time zone definitions
  329. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  330. The :attr:`~django.contrib.admin.ModelAdmin.date_hierarchy` feature of the
  331. admin now relies on :meth:`QuerySet.datetimes()
  332. <django.db.models.query.QuerySet.datetimes>` when it's used on a
  333. :class:`~django.db.models.DateTimeField`.
  334. This requires time zone definitions in the database when :setting:`USE_TZ` is
  335. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  336. ``date_list`` in generic views requires time zone definitions
  337. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  338. For the same reason, accessing ``date_list`` in the context of a date-based
  339. generic view requires time zone definitions in the database when the view is
  340. based on a :class:`~django.db.models.DateTimeField` and :setting:`USE_TZ` is
  341. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  342. New lookups may clash with model fields
  343. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  344. Django 1.6 introduces ``hour``, ``minute``, and ``second`` lookups on
  345. :class:`~django.db.models.DateTimeField`. If you had model fields called
  346. ``hour``, ``minute``, or ``second``, the new lookups will clash with you field
  347. names. Append an explicit :lookup:`exact` lookup if this is an issue.
  348. ``BooleanField`` no longer defaults to ``False``
  349. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  350. When a :class:`~django.db.models.BooleanField` doesn't have an explicit
  351. :attr:`~django.db.models.Field.default`, the implicit default value is
  352. ``None``. In previous version of Django, it was ``False``, but that didn't
  353. represent accurately the lack of a value.
  354. Code that relies on the default value being ``False`` may raise an exception
  355. when saving new model instances to the database, because ``None`` isn't an
  356. acceptable value for a :class:`~django.db.models.BooleanField`. You should
  357. either specify ``default=False`` in the field definition, or ensure the field
  358. is set to ``True`` or ``False`` before saving the object.
  359. Translations and comments in templates
  360. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361. Extraction of translations after comments
  362. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  363. Extraction of translatable literals from templates with the
  364. :djadmin:`makemessages` command now correctly detects i18n constructs when
  365. they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
  366. .. code-block:: html+django
  367. {# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
  368. Location of translator comments
  369. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  370. :ref:`translator-comments-in-templates` specified using ``{#`` / ``#}`` need to
  371. be at the end of a line. If they are not, the comments are ignored and
  372. :djadmin:`makemessages` will generate a warning. For example:
  373. .. code-block:: html+django
  374. {# Translators: This is ignored #}{% trans "Translate me" %}
  375. {{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
  376. <h1>{% trans "Welcome" %}</h1>
  377. Quoting in :func:`~django.core.urlresolvers.reverse`
  378. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  379. When reversing URLs, Django didn't apply :func:`~django.utils.http.urlquote`
  380. to arguments before interpolating them in URL patterns. This bug is fixed in
  381. Django 1.6. If you worked around this bug by applying URL quoting before
  382. passing arguments to :func:`~django.core.urlresolvers.reverse`, this may
  383. result in double-quoting. If this happens, simply remove the URL quoting from
  384. your code.
  385. Storage of IP addresses in the comments app
  386. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  387. The :doc:`comments </ref/contrib/comments/index>` app now uses a
  388. ``GenericIPAddressField`` for storing commenters' IP addresses, to support
  389. comments submitted from IPv6 addresses. Until now, it stored them in an
  390. ``IPAddressField``, which is only meant to support IPv4. When saving a comment
  391. made from an IPv6 address, the address would be silently truncated on MySQL
  392. databases, and raise an exception on Oracle. You will need to change the
  393. column type in your database to benefit from this change.
  394. For MySQL, execute this query on your project's database:
  395. .. code-block:: sql
  396. ALTER TABLE django_comments MODIFY ip_address VARCHAR(39);
  397. For Oracle, execute this query:
  398. .. code-block:: sql
  399. ALTER TABLE DJANGO_COMMENTS MODIFY (ip_address VARCHAR2(39));
  400. If you do not apply this change, the behavior is unchanged: on MySQL, IPv6
  401. addresses are silently truncated; on Oracle, an exception is generated. No
  402. database change is needed for SQLite or PostgreSQL databases.
  403. Percent literals in ``cursor.execute`` queries
  404. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  405. When you are running raw SQL queries through the
  406. :ref:`cursor.execute <executing-custom-sql>` method, the rule about doubling
  407. percent literals (``%``) inside the query has been unified. Past behavior
  408. depended on the database backend. Now, across all backends, you only need to
  409. double literal percent characters if you are also providing replacement
  410. parameters. For example::
  411. # No parameters, no percent doubling
  412. cursor.execute("SELECT foo FROM bar WHERE baz = '30%'")
  413. # Parameters passed, non-placeholders have to be doubled
  414. cursor.execute("SELECT foo FROM bar WHERE baz = '30%%' and id = %s", [self.id])
  415. ``SQLite`` users need to check and update such queries.
  416. .. _m2m-help_text:
  417. Help text of model form fields for ManyToManyField fields
  418. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  419. HTML rendering of model form fields corresponding to
  420. :class:`~django.db.models.ManyToManyField` ORM model fields used to get the
  421. hard-coded sentence
  422. *Hold down "Control", or "Command" on a Mac, to select more than one.*
  423. (or its translation to the active locale) imposed as the help legend shown along
  424. them if neither :attr:`model <django.db.models.Field.help_text>` nor :attr:`form
  425. <django.forms.Field.help_text>` ``help_text`` attribute was specified by the
  426. user (or appended to, if ``help_text`` was provided.)
  427. This happened always, possibly even with form fields implementing user
  428. interactions that don't involve a keyboard and/or a mouse and was handled at the
  429. model field layer.
  430. Starting with Django 1.6 this doesn't happen anymore.
  431. The change can affect you in a backward incompatible way if you employ custom
  432. model form fields and/or widgets for ``ManyToManyField`` model fields whose UIs
  433. do rely on the automatic provision of the mentioned hard-coded sentence. These
  434. form field implementations need to adapt to the new scenario by providing their
  435. own handling of the ``help_text`` attribute.
  436. Applications that use Django :doc:`model form </topics/forms/modelforms>`
  437. facilities together with Django built-in form :doc:`fields </ref/forms/fields>`
  438. and :doc:`widgets </ref/forms/widgets>` aren't affected but need to be aware of
  439. what's described in :ref:`m2m-help_text-deprecation` below.
  440. This is because, as an ad-hoc temporary backward-compatibility provision, the
  441. described non-standard behavior has been preserved but moved to the model form
  442. field layer and occurs only when the associated widget is
  443. :class:`~django.forms.SelectMultiple` or selected subclasses.
  444. QuerySet iteration
  445. ~~~~~~~~~~~~~~~~~~
  446. The ``QuerySet`` iteration was changed to immediately convert all fetched
  447. rows to ``Model`` objects. In Django 1.5 and earlier the fetched rows were
  448. converted to ``Model`` objects in chunks of 100.
  449. Existing code will work, but the amount of rows converted to objects
  450. might change in certain use cases. Such usages include partially looping
  451. over a queryset or any usage which ends up doing ``__bool__`` or
  452. ``__contains__``.
  453. Notably most database backends did fetch all the rows in one go already in
  454. 1.5.
  455. It is still possible to convert the fetched rows to ``Model`` objects
  456. lazily by using the :meth:`~django.db.models.query.QuerySet.iterator()`
  457. method.
  458. :meth:`BoundField.label_tag<django.forms.BoundField.label_tag>` now includes the form's :attr:`~django.forms.Form.label_suffix`
  459. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  460. This is consistent with how methods like
  461. :meth:`Form.as_p<django.forms.Form.as_p>` and
  462. :meth:`Form.as_ul<django.forms.Form.as_ul>` render labels.
  463. If you manually render ``label_tag`` in your templates:
  464. .. code-block:: html+django
  465. {{ form.my_field.label_tag }}: {{ form.my_field }}
  466. you'll want to remove the semicolon (or whatever other separator you may be
  467. using) to avoid duplicating it when upgrading to Django 1.6. The following
  468. template in Django 1.6 will render identically to the above template in Django
  469. 1.5, except that the semicolon will appear inside the ``<label>`` element.
  470. .. code-block:: html+django
  471. {{ form.my_field.label_tag }} {{ form.my_field }}
  472. will render something like:
  473. .. code-block:: html
  474. <label for="id_my_field">My Field:</label> <input id="id_my_field" type="text" name="my_field" />
  475. If you want to keep the current behavior of rendering ``label_tag`` without
  476. the ``label_suffix``, instantiate the form ``label_suffix=''``.
  477. Admin views ``_changelist_filters`` GET parameter
  478. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  479. To achieve preserving and restoring list view filters, admin views now
  480. pass around the `_changelist_filters` GET parameter. It's important that you
  481. account for that change if you have custom admin templates or if your tests
  482. rely on the previous URLs. If you want to revert to the original behavior you
  483. can set the
  484. :attr:`~django.contrib.admin.ModelAdmin.preserve_filters` attribute to ``False``.
  485. Miscellaneous
  486. ~~~~~~~~~~~~~
  487. * The ``django.db.models.query.EmptyQuerySet`` can't be instantiated any more -
  488. it is only usable as a marker class for checking if
  489. :meth:`~django.db.models.query.QuerySet.none` has been called:
  490. ``isinstance(qs.none(), EmptyQuerySet)``
  491. * If your CSS/Javascript code used to access HTML input widgets by type, you
  492. should review it as ``type='text'`` widgets might be now output as
  493. ``type='email'``, ``type='url'`` or ``type='number'`` depending on their
  494. corresponding field type.
  495. * Form field's :attr:`~django.forms.Field.error_messages` that contain a
  496. placeholder should now always use a named placeholder (``"Value '%(value)s' is
  497. too big"`` instead of ``"Value '%s' is too big"``). See the corresponding
  498. field documentation for details about the names of the placeholders. The
  499. changes in 1.6 particularly affect :class:`~django.forms.DecimalField` and
  500. :class:`~django.forms.ModelMultipleChoiceField`.
  501. * There have been changes in the way timeouts are handled in cache backends.
  502. Explicitly passing in ``timeout=None`` no longer results in using the
  503. default timeout. It will now set a non-expiring timeout. Passing 0 into the
  504. memcache backend no longer uses the default timeout, and now will
  505. set-and-expire-immediately the value.
  506. * The ``django.contrib.flatpages`` app used to set custom HTTP headers for
  507. debugging purposes. This functionality was not documented and made caching
  508. ineffective so it has been removed, along with its generic implementation,
  509. previously available in ``django.core.xheaders``.
  510. * The ``XViewMiddleware`` has been moved from ``django.middleware.doc`` to
  511. ``django.contrib.admindocs.middleware`` because it is an implementation
  512. detail of admindocs, proven not to be reusable in general.
  513. * :class:`~django.db.models.GenericIPAddressField` will now only allow
  514. ``blank`` values if ``null`` values are also allowed. Creating a
  515. ``GenericIPAddressField`` where ``blank`` is allowed but ``null`` is not
  516. will trigger a model validation error because ``blank`` values are always
  517. stored as ``null``. Previously, storing a ``blank`` value in a field which
  518. did not allow ``null`` would cause a database exception at runtime.
  519. * If a :class:`~django.core.urlresolvers.NoReverseMatch` exception is raised
  520. from a method when rendering a template, it is not silenced. For example,
  521. ``{{ obj.view_href }}`` will cause template rendering to fail if
  522. ``view_href()`` raises ``NoReverseMatch``. There is no change to the
  523. ``{% url %}`` tag, it causes template rendering to fail like always when
  524. ``NoReverseMatch`` is risen.
  525. * :meth:`django.test.client.Client.logout` now calls
  526. :meth:`django.contrib.auth.logout` which will send the
  527. :func:`~django.contrib.auth.signals.user_logged_out` signal.
  528. * :ref:`Authentication views <built-in-auth-views>` are now reversed by name,
  529. not their locations in ``django.contrib.auth.views``. If you are using the
  530. views without a ``name``, you should update your ``urlpatterns`` to use
  531. :meth:`~django.conf.urls.url` with the ``name`` parameter. For example::
  532. (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete')
  533. becomes::
  534. url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete')
  535. * :class:`~django.views.generic.base.RedirectView` now has a `pattern_name`
  536. attribute which allows it to choose the target by reversing the URL.
  537. * In Django 1.4 and 1.5, a blank string was unintentionally not considered to
  538. be a valid password. This meant
  539. :meth:`~django.contrib.auth.models.User.set_password()` would save a blank
  540. password as an unusable password like
  541. :meth:`~django.contrib.auth.models.User.set_unusable_password()` does, and
  542. thus :meth:`~django.contrib.auth.models.User.check_password()` always
  543. returned ``False`` for blank passwords. This has been corrected in this
  544. release: blank passwords are now valid.
  545. * The admin :attr:`~django.contrib.admin.ModelAdmin.changelist_view` previously
  546. accepted a ``pop`` GET parameter to signify it was to be displayed in a popup.
  547. This parameter has been renamed to ``_popup`` to be consistent with the rest
  548. of the admin views. You should update your custom templates if they use the
  549. previous parameter name.
  550. Features deprecated in 1.6
  551. ==========================
  552. Transaction management APIs
  553. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  554. Transaction management was completely overhauled in Django 1.6, and the
  555. current APIs are deprecated:
  556. - ``django.middleware.transaction.TransactionMiddleware``
  557. - ``django.db.transaction.autocommit``
  558. - ``django.db.transaction.commit_on_success``
  559. - ``django.db.transaction.commit_manually``
  560. - the ``TRANSACTIONS_MANAGED`` setting
  561. The reasons for this change and the upgrade path are described in the
  562. :ref:`transactions documentation <transactions-upgrading-from-1.5>`.
  563. ``django.contrib.comments``
  564. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  565. Django's comment framework has been deprecated and is no longer supported. It
  566. will be available in Django 1.6 and 1.7, and removed in Django 1.8. Most users
  567. will be better served with a custom solution, or a hosted product like Disqus__.
  568. The code formerly known as ``django.contrib.comments`` is `still available
  569. in an external repository`__.
  570. __ https://disqus.com/
  571. __ https://github.com/django/django-contrib-comments
  572. Support for PostgreSQL versions older than 8.4
  573. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  574. The end of upstream support periods was reached in December 2011 for
  575. PostgreSQL 8.2 and in February 2013 for 8.3. As a consequence, Django 1.6 sets
  576. 8.4 as the minimum PostgreSQL version it officially supports.
  577. You're strongly encouraged to use the most recent version of PostgreSQL
  578. available, because of performance improvements and to take advantage of the
  579. native streaming replication available in PostgreSQL 9.x.
  580. Changes to :ttag:`cycle` and :ttag:`firstof`
  581. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  582. The template system generally escapes all variables to avoid XSS attacks.
  583. However, due to an accident of history, the :ttag:`cycle` and :ttag:`firstof`
  584. tags render their arguments as-is.
  585. Django 1.6 starts a process to correct this inconsistency. The ``future``
  586. template library provides alternate implementations of :ttag:`cycle` and
  587. :ttag:`firstof` that autoescape their inputs. If you're using these tags,
  588. you're encourage to include the following line at the top of your templates to
  589. enable the new behavior::
  590. {% load cycle from future %}
  591. or::
  592. {% load firstof from future %}
  593. The tags implementing the old behavior have been deprecated, and in Django
  594. 1.8, the old behavior will be replaced with the new behavior. To ensure
  595. compatibility with future versions of Django, existing templates should be
  596. modified to use the ``future`` versions.
  597. If necessary, you can temporarily disable auto-escaping with
  598. :func:`~django.utils.safestring.mark_safe` or :ttag:`{% autoescape off %}
  599. <autoescape>`.
  600. ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting
  601. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  602. ``CacheMiddleware`` used to provide a way to cache requests only if they
  603. weren't made by a logged-in user. This mechanism was largely ineffective
  604. because the middleware correctly takes into account the ``Vary: Cookie`` HTTP
  605. header, and this header is being set on a variety of occasions, such as:
  606. * accessing the session, or
  607. * using CSRF protection, which is turned on by default, or
  608. * using a client-side library which sets cookies, like `Google Analytics`__.
  609. This makes the cache effectively work on a per-session basis regardless of the
  610. ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting.
  611. __ http://www.google.com/analytics/
  612. ``SEND_BROKEN_LINK_EMAILS`` setting
  613. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  614. :class:`~django.middleware.common.CommonMiddleware` used to provide basic
  615. reporting of broken links by email when ``SEND_BROKEN_LINK_EMAILS`` is set to
  616. ``True``.
  617. Because of intractable ordering problems between
  618. :class:`~django.middleware.common.CommonMiddleware` and
  619. :class:`~django.middleware.locale.LocaleMiddleware`, this feature was split
  620. out into a new middleware:
  621. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware`.
  622. If you're relying on this feature, you should add
  623. ``'django.middleware.common.BrokenLinkEmailsMiddleware'`` to your
  624. :setting:`MIDDLEWARE_CLASSES` setting and remove ``SEND_BROKEN_LINK_EMAILS``
  625. from your settings.
  626. ``_has_changed`` method on widgets
  627. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  628. If you defined your own form widgets and defined the ``_has_changed`` method
  629. on a widget, you should now define this method on the form field itself.
  630. ``module_name`` model _meta attribute
  631. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  632. ``Model._meta.module_name`` was renamed to ``model_name``. Despite being a
  633. private API, it will go through a regular deprecation path.
  634. ``get_query_set`` and similar methods renamed to ``get_queryset``
  635. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  636. Methods that return a ``QuerySet`` such as ``Manager.get_query_set`` or
  637. ``ModelAdmin.queryset`` have been renamed to ``get_queryset``.
  638. ``shortcut`` view and URLconf
  639. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  640. The ``shortcut`` view was moved from ``django.views.defaults`` to
  641. ``django.contrib.contenttypes.views`` shortly after the 1.0 release, but the
  642. old location was never deprecated. This oversight was corrected in Django 1.6
  643. and you should now use the new location.
  644. The URLconf ``django.conf.urls.shortcut`` was also deprecated. If you're
  645. including it in an URLconf, simply replace::
  646. (r'^prefix/', include('django.conf.urls.shortcut')),
  647. with::
  648. (r'^prefix/(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'django.contrib.contenttypes.views.shortcut'),
  649. ``ModelForm`` without ``fields`` or ``exclude``
  650. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  651. Previously, if you wanted a :class:`~django.forms.ModelForm` to use all fields on
  652. the model, you could simply omit the ``Meta.fields`` attribute, and all fields
  653. would be used.
  654. This can lead to security problems where fields are added to the model and,
  655. unintentionally, automatically become editable by end users. In some cases,
  656. particular with boolean fields, it is possible for this problem to be completely
  657. invisible. This is a form of `Mass assignment vulnerability
  658. <http://en.wikipedia.org/wiki/Mass_assignment_vulnerability>`_.
  659. For this reason, this behavior is deprecated, and using the ``Meta.exclude``
  660. option is strongly discouraged. Instead, all fields that are intended for
  661. inclusion in the form should be listed explicitly in the ``fields`` attribute.
  662. If this security concern really does not apply in your case, there is a shortcut
  663. to explicitly indicate that all fields should be used - use the special value
  664. ``"__all__"`` for the fields attribute::
  665. class MyModelForm(ModelForm):
  666. class Meta:
  667. fields = "__all__"
  668. model = MyModel
  669. If you have custom ``ModelForms`` that only need to be used in the admin, there
  670. is another option. The admin has its own methods for defining fields
  671. (``fieldsets`` etc.), and so adding a list of fields to the ``ModelForm`` is
  672. redundant. Instead, simply omit the ``Meta`` inner class of the ``ModelForm``,
  673. or omit the ``Meta.model`` attribute. Since the ``ModelAdmin`` subclass knows
  674. which model it is for, it can add the necessary attributes to derive a
  675. functioning ``ModelForm``. This behavior also works for earlier Django
  676. versions.
  677. ``UpdateView`` and ``CreateView`` without explicit fields
  678. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  679. The generic views :class:`~django.views.generic.edit.CreateView` and
  680. :class:`~django.views.generic.edit.UpdateView`, and anything else derived from
  681. :class:`~django.views.generic.edit.ModelFormMixin`, are vulnerable to the
  682. security problem described in the section above, because they can automatically
  683. create a ``ModelForm`` that uses all fields for a model.
  684. For this reason, if you use these views for editing models, you must also supply
  685. the ``fields`` attribute, which is a list of model fields and works in the same
  686. way as the :class:`~django.forms.ModelForm` ``Meta.fields`` attribute. Alternatively,
  687. you can set set the ``form_class`` attribute to a ``ModelForm`` that explicitly
  688. defines the fields to be used. Defining an ``UpdateView`` or ``CreateView``
  689. subclass to be used with a model but without an explicit list of fields is
  690. deprecated.
  691. .. _m2m-help_text-deprecation:
  692. Munging of help text of model form fields for ``ManyToManyField`` fields
  693. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  694. All special handling of the ``help_text`` attribute of ``ManyToManyField`` model
  695. fields performed by standard model or model form fields as described in
  696. :ref:`m2m-help_text` above is deprecated and will be removed in Django 1.8.
  697. Help text of these fields will need to be handled either by applications, custom
  698. form fields or widgets, just like happens with the rest of the model field
  699. types.