1.6.txt 28 KB

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