1.6.txt 29 KB

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