1.6.txt 34 KB

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