1.6.txt 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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.DjangoTestDiscoverRunner``) uses the test
  61. discovery features built into unittest2 (the version of unittest in the Python
  62. 2.7+ standard library, and bundled with Django). With test discovery, tests can
  63. 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 to store 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. Minor features
  93. ~~~~~~~~~~~~~~
  94. * Authentication backends can raise ``PermissionDenied`` to immediately fail
  95. the authentication chain.
  96. * The HttpOnly flag can be set on the CSRF cookie with
  97. :setting:`CSRF_COOKIE_HTTPONLY`.
  98. * The ``assertQuerysetEqual()`` now checks for undefined order and raises
  99. ``ValueError`` if undefined order is spotted. The order is seen as
  100. undefined if the given ``QuerySet`` isn't ordered and there are more than
  101. one ordered values to compare against.
  102. * Added :meth:`~django.db.models.query.QuerySet.earliest` for symmetry with
  103. :meth:`~django.db.models.query.QuerySet.latest`.
  104. * In addition to :lookup:`year`, :lookup:`month` and :lookup:`day`, the ORM
  105. now supports :lookup:`hour`, :lookup:`minute` and :lookup:`second` lookups.
  106. * Django now wraps all PEP-249 exceptions.
  107. * The default widgets for :class:`~django.forms.EmailField`,
  108. :class:`~django.forms.URLField`, :class:`~django.forms.IntegerField`,
  109. :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` use
  110. the new type attributes available in HTML5 (type='email', type='url',
  111. type='number'). Note that due to erratic support of the ``number`` input type
  112. with localized numbers in current browsers, Django only uses it when numeric
  113. fields are not localized.
  114. * The ``number`` argument for :ref:`lazy plural translations
  115. <lazy-plural-translations>` can be provided at translation time rather than
  116. at definition time.
  117. * For custom management commands: Verification of the presence of valid
  118. settings in commands that ask for it by using the
  119. :attr:`~django.core.management.BaseCommand.can_import_settings` internal
  120. option is now performed independently from handling of the locale that
  121. should be active during the execution of the command. The latter can now be
  122. influenced by the new
  123. :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal
  124. option. See :ref:`management-commands-and-locales` for more details.
  125. * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of
  126. :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with
  127. its ``object``\'s ``__dict__``.
  128. * :class:`~django.http.HttpResponseRedirect` and
  129. :class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
  130. attribute (equivalent to the URL the response will redirect to).
  131. * The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
  132. protocol available.
  133. * Added :class:`~django.contrib.messages.views.SuccessMessageMixin` which
  134. provides a ``success_message`` attribute for
  135. :class:`~django.views.generic.edit.FormView` based classes.
  136. * Added the :attr:`django.db.models.ForeignKey.db_constraint` and
  137. :attr:`django.db.models.ManyToManyField.db_constraint` options.
  138. * The jQuery library embedded in the admin has been upgraded to version 1.9.1.
  139. * Syndication feeds (:mod:`django.contrib.syndication`) can now pass extra
  140. context through to feed templates using a new `Feed.get_context_data()`
  141. callback.
  142. * The admin list columns have a ``column-<field_name>`` class in the HTML
  143. so the columns header can be styled with CSS, e.g. to set a column width.
  144. * The isolation level can be customized under PostgreSQL.
  145. * The :ttag:`blocktrans` template tag now respects
  146. :setting:`TEMPLATE_STRING_IF_INVALID` for variables not present in the
  147. context, just like other template constructs.
  148. * SimpleLazyObjects will now present more helpful representations in shell
  149. debugging situations.
  150. * Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
  151. with the OpenLayers widget in the admin.
  152. * The :meth:`Model.save() <django.db.models.Model.save()>` will do
  153. ``UPDATE`` - if not updated - ``INSERT`` instead of ``SELECT`` - if not
  154. found ``INSERT`` else ``UPDATE`` in case the model's primary key is set.
  155. * The documentation contains a :doc:`deployment checklist
  156. </howto/deployment/checklist>`.
  157. * The :djadmin:`diffsettings` comand gained a ``--all`` option.
  158. * ``django.forms.fields.Field.__init__`` now calls ``super()``, allowing
  159. field mixins to implement ``__init__()`` methods that will reliably be
  160. called.
  161. * The ``validate_max`` parameter was added to ``BaseFormSet`` and
  162. :func:`~django.forms.formsets.formset_factory`, and ``ModelForm`` and inline
  163. versions of the same. The behavior of validation for formsets with
  164. ``max_num`` was clarified. The previously undocumented behavior that
  165. hardened formsets against memory exhaustion attacks was documented,
  166. and the undocumented limit of the higher of 1000 or ``max_num`` forms
  167. was changed so it is always 1000 more than ``max_num``.
  168. * Added ``BCryptSHA256PasswordHasher`` to resolve the password truncation issue
  169. with bcrypt.
  170. * `Pillow`_ is now the preferred image manipulation library to use with Django.
  171. `PIL`_ is pending deprecation (support to be removed in Django 1.8).
  172. To upgrade, you should **first** uninstall PIL, **then** install Pillow.
  173. .. _`Pillow`: https://pypi.python.org/pypi/Pillow
  174. .. _`PIL`: https://pypi.python.org/pypi/PIL
  175. Backwards incompatible changes in 1.6
  176. =====================================
  177. .. warning::
  178. In addition to the changes outlined in this section, be sure to review the
  179. :doc:`deprecation plan </internals/deprecation>` for any features that
  180. have been removed. If you haven't updated your code within the
  181. deprecation timeline for a given feature, its removal may appear as a
  182. backwards incompatible change.
  183. New transaction management model
  184. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185. Behavior changes
  186. ^^^^^^^^^^^^^^^^
  187. Database-level autocommit is enabled by default in Django 1.6. While this
  188. doesn't change the general spirit of Django's transaction management, there
  189. are a few known backwards-incompatibities, described in the :ref:`transaction
  190. management docs <transactions-upgrading-from-1.5>`. You should review your
  191. code to determine if you're affected.
  192. Savepoints and ``assertNumQueries``
  193. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  194. The changes in transaction management may result in additional statements to
  195. create, release or rollback savepoints. This is more likely to happen with
  196. SQLite, since it didn't support savepoints until this release.
  197. If tests using :meth:`~django.test.TestCase.assertNumQueries` fail because of
  198. a higher number of queries than expected, check that the extra queries are
  199. related to savepoints, and adjust the expected number of queries accordingly.
  200. Autocommit option for PostgreSQL
  201. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  202. In previous versions, database-level autocommit was only an option for
  203. PostgreSQL, and it was disabled by default. This option is now :ref:`ignored
  204. <postgresql-autocommit-mode>` and can be removed.
  205. .. _new-test-runner:
  206. New test runner
  207. ~~~~~~~~~~~~~~~
  208. In order to maintain greater consistency with Python's unittest module, the new
  209. test runner (``django.test.runner.DiscoverRunner``) does not automatically
  210. support some types of tests that were supported by the previous runner:
  211. * Tests in ``models.py`` and ``tests/__init__.py`` files will no longer be
  212. found and run. Move them to a file whose name begins with ``test``.
  213. * Doctests will no longer be automatically discovered. To integrate doctests in
  214. your test suite, follow the `recommendations in the Python documentation`_.
  215. Django bundles a modified version of the :mod:`doctest` module from the Python
  216. standard library (in ``django.test._doctest``) in order to allow passing in a
  217. custom ``DocTestRunner`` when instantiating a ``DocTestSuite``, and includes
  218. some additional doctest utilities (``django.test.testcases.DocTestRunner``
  219. turns on the ``ELLIPSIS`` option by default, and
  220. ``django.test.testcases.OutputChecker`` provides better matching of XML, JSON,
  221. and numeric data types).
  222. These utilities are deprecated and will be removed in Django 1.8; doctest
  223. suites should be updated to work with the standard library's doctest module (or
  224. converted to unittest-compatible tests).
  225. If you wish to delay updates to your test suite, you can set your
  226. :setting:`TEST_RUNNER` setting to ``django.test.simple.DjangoTestSuiteRunner``
  227. to fully restore the old test behavior. ``DjangoTestSuiteRunner`` is
  228. deprecated but will not be removed from Django until version 1.8.
  229. .. _recommendations in the Python documentation: http://docs.python.org/2/library/doctest.html#unittest-api
  230. Addition of ``QuerySet.datetimes()``
  231. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  232. When the :doc:`time zone support </topics/i18n/timezones>` added in Django 1.4
  233. was active, :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>`
  234. lookups returned unexpected results, because the aggregation was performed in
  235. UTC. To fix this, Django 1.6 introduces a new API, :meth:`QuerySet.datetimes()
  236. <django.db.models.query.QuerySet.datetimes>`. This requires a few changes in
  237. your code.
  238. ``QuerySet.dates()`` returns ``date`` objects
  239. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  240. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` now returns a
  241. list of :class:`~datetime.date`. It used to return a list of
  242. :class:`~datetime.datetime`.
  243. :meth:`QuerySet.datetimes() <django.db.models.query.QuerySet.datetimes>`
  244. returns a list of :class:`~datetime.datetime`.
  245. ``QuerySet.dates()`` no longer usable on ``DateTimeField``
  246. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  247. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` raises an
  248. error if it's used on :class:`~django.db.models.DateTimeField` when time
  249. zone support is active. Use :meth:`QuerySet.datetimes()
  250. <django.db.models.query.QuerySet.datetimes>` instead.
  251. ``date_hierarchy`` requires time zone definitions
  252. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  253. The :attr:`~django.contrib.admin.ModelAdmin.date_hierarchy` feature of the
  254. admin now relies on :meth:`QuerySet.datetimes()
  255. <django.db.models.query.QuerySet.datetimes>` when it's used on a
  256. :class:`~django.db.models.DateTimeField`.
  257. This requires time zone definitions in the database when :setting:`USE_TZ` is
  258. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  259. ``date_list`` in generic views requires time zone definitions
  260. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  261. For the same reason, accessing ``date_list`` in the context of a date-based
  262. generic view requires time zone definitions in the database when the view is
  263. based on a :class:`~django.db.models.DateTimeField` and :setting:`USE_TZ` is
  264. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  265. New lookups may clash with model fields
  266. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  267. Django 1.6 introduces ``hour``, ``minute``, and ``second`` lookups on
  268. :class:`~django.db.models.DateTimeField`. If you had model fields called
  269. ``hour``, ``minute``, or ``second``, the new lookups will clash with you field
  270. names. Append an explicit :lookup:`exact` lookup if this is an issue.
  271. ``BooleanField`` no longer defaults to ``False``
  272. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  273. When a :class:`~django.db.models.BooleanField` doesn't have an explicit
  274. :attr:`~django.db.models.Field.default`, the implicit default value is
  275. ``None``. In previous version of Django, it was ``False``, but that didn't
  276. represent accurately the lack of a value.
  277. Code that relies on the default value being ``False`` may raise an exception
  278. when saving new model instances to the database, because ``None`` isn't an
  279. acceptable value for a :class:`~django.db.models.BooleanField`. You should
  280. either specify ``default=False`` in the field definition, or ensure the field
  281. is set to ``True`` or ``False`` before saving the object.
  282. Translations and comments in templates
  283. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  284. Extraction of translations after comments
  285. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  286. Extraction of translatable literals from templates with the
  287. :djadmin:`makemessages` command now correctly detects i18n constructs when
  288. they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
  289. .. code-block:: html+django
  290. {# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
  291. Location of translator comments
  292. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  293. Validation of the placement of :ref:`translator-comments-in-templates`
  294. specified using ``{#`` / ``#}`` is now stricter. All translator comments not
  295. located at the end of their respective lines in a template are ignored and a
  296. warning is generated by :djadmin:`makemessages` when it finds them. E.g.:
  297. .. code-block:: html+django
  298. {# Translators: This is ignored #}{% trans "Translate me" %}
  299. {{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
  300. <h1>{% trans "Welcome" %}</h1>
  301. Quoting in :func:`~django.core.urlresolvers.reverse`
  302. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  303. When reversing URLs, Django didn't apply :func:`~django.utils.http.urlquote`
  304. to arguments before interpolating them in URL patterns. This bug is fixed in
  305. Django 1.6. If you worked around this bug by applying URL quoting before
  306. passing arguments to :func:`~django.core.urlresolvers.reverse`, this may
  307. result in double-quoting. If this happens, simply remove the URL quoting from
  308. your code.
  309. Storage of IP addresses in the comments app
  310. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  311. The :doc:`comments </ref/contrib/comments/index>` app now uses a
  312. ``GenericIPAddressField`` for storing commenters' IP addresses, to support
  313. comments submitted from IPv6 addresses. Until now, it stored them in an
  314. ``IPAddressField``, which is only meant to support IPv4. When saving a comment
  315. made from an IPv6 address, the address would be silently truncated on MySQL
  316. databases, and raise an exception on Oracle. You will need to change the
  317. column type in your database to benefit from this change.
  318. For MySQL, execute this query on your project's database:
  319. .. code-block:: sql
  320. ALTER TABLE django_comments MODIFY ip_address VARCHAR(39);
  321. For Oracle, execute this query:
  322. .. code-block:: sql
  323. ALTER TABLE DJANGO_COMMENTS MODIFY (ip_address VARCHAR2(39));
  324. If you do not apply this change, the behaviour is unchanged: on MySQL, IPv6
  325. addresses are silently truncated; on Oracle, an exception is generated. No
  326. database change is needed for SQLite or PostgreSQL databases.
  327. Percent literals in ``cursor.execute`` queries
  328. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  329. When you are running raw SQL queries through the
  330. :ref:`cursor.execute <executing-custom-sql>` method, the rule about doubling
  331. percent literals (``%``) inside the query has been unified. Past behavior
  332. depended on the database backend. Now, across all backends, you only need to
  333. double literal percent characters if you are also providing replacement
  334. parameters. For example::
  335. # No parameters, no percent doubling
  336. cursor.execute("SELECT foo FROM bar WHERE baz = '30%'")
  337. # Parameters passed, non-placeholders have to be doubled
  338. cursor.execute("SELECT foo FROM bar WHERE baz = '30%%' and id = %s", [self.id])
  339. ``SQLite`` users need to check and update such queries.
  340. Miscellaneous
  341. ~~~~~~~~~~~~~
  342. * The ``django.db.models.query.EmptyQuerySet`` can't be instantiated any more -
  343. it is only usable as a marker class for checking if
  344. :meth:`~django.db.models.query.QuerySet.none` has been called:
  345. ``isinstance(qs.none(), EmptyQuerySet)``
  346. * If your CSS/Javascript code used to access HTML input widgets by type, you
  347. should review it as ``type='text'`` widgets might be now output as
  348. ``type='email'``, ``type='url'`` or ``type='number'`` depending on their
  349. corresponding field type.
  350. * Form field's :attr:`~django.forms.Field.error_messages` that contain a
  351. placeholder should now always use a named placeholder (``"Value '%(value)s' is
  352. too big"`` instead of ``"Value '%s' is too big"``). See the corresponding
  353. field documentation for details about the names of the placeholders. The
  354. changes in 1.6 particularly affect :class:`~django.forms.DecimalField` and
  355. :class:`~django.forms.ModelMultipleChoiceField`.
  356. Features deprecated in 1.6
  357. ==========================
  358. Transaction management APIs
  359. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  360. Transaction management was completely overhauled in Django 1.6, and the
  361. current APIs are deprecated:
  362. - ``django.middleware.transaction.TransactionMiddleware``
  363. - ``django.db.transaction.autocommit``
  364. - ``django.db.transaction.commit_on_success``
  365. - ``django.db.transaction.commit_manually``
  366. - the ``TRANSACTIONS_MANAGED`` setting
  367. The reasons for this change and the upgrade path are described in the
  368. :ref:`transactions documentation <transactions-upgrading-from-1.5>`.
  369. ``django.contrib.comments``
  370. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  371. Django's comment framework has been deprecated and is no longer supported. It
  372. will be available in Django 1.6 and 1.7, and removed in Django 1.8. Most users
  373. will be better served with a custom solution, or a hosted product like Disqus__.
  374. The code formerly known as ``django.contrib.comments`` is `still available
  375. in an external repository`__.
  376. __ https://disqus.com/
  377. __ https://github.com/django/django-contrib-comments
  378. Support for PostgreSQL versions older than 8.4
  379. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  380. The end of upstream support periods was reached in December 2011 for
  381. PostgreSQL 8.2 and in February 2013 for 8.3. As a consequence, Django 1.6 sets
  382. 8.4 as the minimum PostgreSQL version it officially supports.
  383. You're strongly encouraged to use the most recent version of PostgreSQL
  384. available, because of performance improvements and to take advantage of the
  385. native streaming replication available in PostgreSQL 9.x.
  386. Changes to :ttag:`cycle` and :ttag:`firstof`
  387. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  388. The template system generally escapes all variables to avoid XSS attacks.
  389. However, due to an accident of history, the :ttag:`cycle` and :ttag:`firstof`
  390. tags render their arguments as-is.
  391. Django 1.6 starts a process to correct this inconsistency. The ``future``
  392. template library provides alternate implementations of :ttag:`cycle` and
  393. :ttag:`firstof` that autoescape their inputs. If you're using these tags,
  394. you're encourage to include the following line at the top of your templates to
  395. enable the new behavior::
  396. {% load cycle from future %}
  397. or::
  398. {% load firstof from future %}
  399. The tags implementing the old behavior have been deprecated, and in Django
  400. 1.8, the old behavior will be replaced with the new behavior. To ensure
  401. compatibility with future versions of Django, existing templates should be
  402. modified to use the ``future`` versions.
  403. If necessary, you can temporarily disable auto-escaping with
  404. :func:`~django.utils.safestring.mark_safe` or :ttag:`{% autoescape off %}
  405. <autoescape>`.
  406. ``SEND_BROKEN_LINK_EMAILS`` setting
  407. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  408. :class:`~django.middleware.common.CommonMiddleware` used to provide basic
  409. reporting of broken links by email when ``SEND_BROKEN_LINK_EMAILS`` is set to
  410. ``True``.
  411. Because of intractable ordering problems between
  412. :class:`~django.middleware.common.CommonMiddleware` and
  413. :class:`~django.middleware.locale.LocaleMiddleware`, this feature was split
  414. out into a new middleware:
  415. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware`.
  416. If you're relying on this feature, you should add
  417. ``'django.middleware.common.BrokenLinkEmailsMiddleware'`` to your
  418. :setting:`MIDDLEWARE_CLASSES` setting and remove ``SEND_BROKEN_LINK_EMAILS``
  419. from your settings.
  420. ``_has_changed`` method on widgets
  421. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  422. If you defined your own form widgets and defined the ``_has_changed`` method
  423. on a widget, you should now define this method on the form field itself.
  424. ``module_name`` model meta attribute
  425. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  426. ``Model._meta.module_name`` was renamed to ``model_name``. Despite being a
  427. private API, it will go through a regular deprecation path.
  428. ``get_query_set`` and similar methods renamed to ``get_queryset``
  429. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  430. Methods that return a ``QuerySet`` such as ``Manager.get_query_set`` or
  431. ``ModelAdmin.queryset`` have been renamed to ``get_queryset``.
  432. ``shortcut`` view and URLconf
  433. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  434. The ``shortcut`` view was moved from ``django.views.defaults`` to
  435. ``django.contrib.contenttypes.views`` shortly after the 1.0 release, but the
  436. old location was never deprecated. This oversight was corrected in Django 1.6
  437. and you should now use the new location.
  438. The URLconf ``django.conf.urls.shortcut`` was also deprecated. If you're
  439. including it in an URLconf, simply replace::
  440. (r'^prefix/', include('django.conf.urls.shortcut')),
  441. with::
  442. (r'^prefix/(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'django.contrib.contenttypes.views.shortcut'),
  443. ``ModelForm`` without ``fields`` or ``exclude``
  444. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  445. Previously, if you wanted a :class:`~django.forms.ModelForm` to use all fields on
  446. the model, you could simply omit the ``Meta.fields`` attribute, and all fields
  447. would be used.
  448. This can lead to security problems where fields are added to the model and,
  449. unintentionally, automatically become editable by end users. In some cases,
  450. particular with boolean fields, it is possible for this problem to be completely
  451. invisible. This is a form of `Mass assignment vulnerability
  452. <http://en.wikipedia.org/wiki/Mass_assignment_vulnerability>`_.
  453. For this reason, this behaviour is deprecated, and using the ``Meta.exclude``
  454. option is strongly discouraged. Instead, all fields that are intended for
  455. inclusion in the form should be listed explicitly in the ``fields`` attribute.
  456. If this security concern really does not apply in your case, there is a shortcut
  457. to explicitly indicate that all fields should be used - use the special value
  458. ``"__all__"`` for the fields attribute::
  459. class MyModelForm(ModelForm):
  460. class Meta:
  461. fields = "__all__"
  462. model = MyModel
  463. If you have custom ``ModelForms`` that only need to be used in the admin, there
  464. is another option. The admin has its own methods for defining fields
  465. (``fieldsets`` etc.), and so adding a list of fields to the ``ModelForm`` is
  466. redundant. Instead, simply omit the ``Meta`` inner class of the ``ModelForm``,
  467. or omit the ``Meta.model`` attribute. Since the ``ModelAdmin`` subclass knows
  468. which model it is for, it can add the necessary attributes to derive a
  469. functioning ``ModelForm``. This behaviour also works for earlier Django
  470. versions.
  471. ``UpdateView`` and ``CreateView`` without explicit fields
  472. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  473. The generic views :class:`~django.views.generic.edit.CreateView` and
  474. :class:`~django.views.generic.edit.UpdateView`, and anything else derived from
  475. :class:`~django.views.generic.edit.ModelFormMixin`, are vulnerable to the
  476. security problem described in the section above, because they can automatically
  477. create a ``ModelForm`` that uses all fields for a model.
  478. For this reason, if you use these views for editing models, you must also supply
  479. the ``fields`` attribute, which is a list of model fields and works in the same
  480. way as the :class:`~django.forms.ModelForm` ``Meta.fields`` attribute. Alternatively,
  481. you can set set the ``form_class`` attribute to a ``ModelForm`` that explicitly
  482. defines the fields to be used. Defining an ``UpdateView`` or ``CreateView``
  483. subclass to be used with a model but without an explicit list of fields is
  484. deprecated.