1. =========================
    
  2.  Django 1.6 release notes
    
  3. =========================
    
  4. 
    
  5. .. note::
    
  6. 
    
  7.     Dedicated to Malcolm Tredinnick
    
  8. 
    
  9.     On March 17, 2013, the Django project and the free software community lost
    
  10.     a very dear friend and developer.
    
  11. 
    
  12.     Malcolm was a long-time contributor to Django, a model community member, a
    
  13.     brilliant mind, and a friend. His contributions to Django — and to many other
    
  14.     open source projects — are nearly impossible to enumerate. Many on the core
    
  15.     Django team had their first patches reviewed by him; his mentorship enriched
    
  16.     us. His consideration, patience, and dedication will always be an inspiration
    
  17.     to us.
    
  18. 
    
  19.     This release of Django is for Malcolm.
    
  20. 
    
  21.     -- The Django Developers
    
  22. 
    
  23. *November 6, 2013*
    
  24. 
    
  25. Welcome to Django 1.6!
    
  26. 
    
  27. These release notes cover the :ref:`new features <whats-new-1.6>`, as well as
    
  28. some :ref:`backwards incompatible changes <backwards-incompatible-1.6>` you'll
    
  29. want to be aware of when upgrading from Django 1.5 or older versions. We've
    
  30. also dropped some features, which are detailed in :ref:`our deprecation plan
    
  31. <deprecation-removed-in-1.6>`, and we've :ref:`begun the deprecation process
    
  32. for some features <deprecated-features-1.6>`.
    
  33. 
    
  34. Python compatibility
    
  35. ====================
    
  36. 
    
  37. Django 1.6, like Django 1.5, requires Python 2.6.5 or above. Python 3 is also
    
  38. officially supported. We **highly recommend** the latest minor release for each
    
  39. supported Python series (2.6.X, 2.7.X, 3.2.X, and 3.3.X).
    
  40. 
    
  41. Django 1.6 will be the final release series to support Python 2.6; beginning
    
  42. with Django 1.7, the minimum supported Python version will be 2.7.
    
  43. 
    
  44. Python 3.4 is not supported, but support will be added in Django 1.7.
    
  45. 
    
  46. .. _whats-new-1.6:
    
  47. 
    
  48. What's new in Django 1.6
    
  49. ========================
    
  50. 
    
  51. Simplified default project and app templates
    
  52. --------------------------------------------
    
  53. 
    
  54. The default templates used by :djadmin:`startproject` and :djadmin:`startapp`
    
  55. have been simplified and modernized. The :doc:`admin
    
  56. </ref/contrib/admin/index>` is now enabled by default in new projects; the
    
  57. :doc:`sites </ref/contrib/sites>` framework no longer is. :ref:`clickjacking
    
  58. prevention <clickjacking-prevention>` is now on and the database defaults to
    
  59. SQLite.
    
  60. 
    
  61. If the default templates don't suit your tastes, you can use :ref:`custom
    
  62. project and app templates <custom-app-and-project-templates>`.
    
  63. 
    
  64. Improved transaction management
    
  65. -------------------------------
    
  66. 
    
  67. Django's transaction management was overhauled. Database-level autocommit is
    
  68. now turned on by default. This makes transaction handling more explicit and
    
  69. should improve performance. The existing APIs were deprecated, and new APIs
    
  70. were introduced, as described in the :doc:`transaction management docs
    
  71. </topics/db/transactions>`.
    
  72. 
    
  73. Persistent database connections
    
  74. -------------------------------
    
  75. 
    
  76. Django now supports reusing the same database connection for several requests.
    
  77. This avoids the overhead of reestablishing a connection at the beginning of
    
  78. each request. For backwards compatibility, this feature is disabled by
    
  79. default. See :ref:`persistent-database-connections` for details.
    
  80. 
    
  81. Discovery of tests in any test module
    
  82. -------------------------------------
    
  83. 
    
  84. Django 1.6 ships with a new test runner that allows more flexibility in the
    
  85. location of tests. The previous runner
    
  86. (``django.test.simple.DjangoTestSuiteRunner``) found tests only in the
    
  87. ``models.py`` and ``tests.py`` modules of a Python package in
    
  88. :setting:`INSTALLED_APPS`.
    
  89. 
    
  90. The new runner (``django.test.runner.DiscoverRunner``) uses the test discovery
    
  91. features built into ``unittest2`` (the version of ``unittest`` in the
    
  92. Python 2.7+ standard library, and bundled with Django). With test discovery,
    
  93. tests can be located in any module whose name matches the pattern ``test*.py``.
    
  94. 
    
  95. In addition, the test labels provided to ``./manage.py test`` to nominate
    
  96. specific tests to run must now be full Python dotted paths (or directory
    
  97. paths), rather than ``applabel.TestCase.test_method_name`` pseudo-paths. This
    
  98. allows running tests located anywhere in your codebase, rather than only in
    
  99. :setting:`INSTALLED_APPS`. For more details, see :doc:`/topics/testing/index`.
    
  100. 
    
  101. This change is backwards-incompatible; see the :ref:`backwards-incompatibility
    
  102. notes<new-test-runner>`.
    
  103. 
    
  104. Time zone aware aggregation
    
  105. ---------------------------
    
  106. 
    
  107. The support for :doc:`time zones </topics/i18n/timezones>` introduced in
    
  108. Django 1.4 didn't work well with :meth:`QuerySet.dates()
    
  109. <django.db.models.query.QuerySet.dates>`: aggregation was always performed in
    
  110. UTC. This limitation was lifted in Django 1.6. Use :meth:`QuerySet.datetimes()
    
  111. <django.db.models.query.QuerySet.datetimes>` to perform time zone aware
    
  112. aggregation on a :class:`~django.db.models.DateTimeField`.
    
  113. 
    
  114. Support for savepoints in SQLite
    
  115. --------------------------------
    
  116. 
    
  117. Django 1.6 adds support for savepoints in SQLite, with some :ref:`limitations
    
  118. <savepoints-in-sqlite>`.
    
  119. 
    
  120. ``BinaryField`` model field
    
  121. ---------------------------
    
  122. 
    
  123. A new :class:`django.db.models.BinaryField` model field allows storage of raw
    
  124. binary data in the database.
    
  125. 
    
  126. GeoDjango form widgets
    
  127. ----------------------
    
  128. 
    
  129. GeoDjango now provides :doc:`form fields and widgets </ref/contrib/gis/forms-api>`
    
  130. for its geo-specialized fields. They are OpenLayers-based by default, but they
    
  131. can be customized to use any other JS framework.
    
  132. 
    
  133. ``check`` management command added for verifying compatibility
    
  134. --------------------------------------------------------------
    
  135. 
    
  136. A :djadmin:`check` management command was added, enabling you to verify if your
    
  137. current configuration (currently oriented at settings) is compatible with the
    
  138. current version of Django.
    
  139. 
    
  140. :meth:`Model.save() <django.db.models.Model.save()>` algorithm changed
    
  141. ----------------------------------------------------------------------
    
  142. 
    
  143. The :meth:`Model.save() <django.db.models.Model.save()>` method now
    
  144. tries to directly ``UPDATE`` the database if the instance has a primary
    
  145. key value. Previously ``SELECT`` was performed to determine if ``UPDATE``
    
  146. or ``INSERT`` were needed. The new algorithm needs only one query for
    
  147. updating an existing row while the old algorithm needed two. See
    
  148. :meth:`Model.save() <django.db.models.Model.save()>` for more details.
    
  149. 
    
  150. In some rare cases the database doesn't report that a matching row was
    
  151. found when doing an ``UPDATE``. An example is the PostgreSQL ``ON UPDATE``
    
  152. trigger which returns ``NULL``. In such cases it is possible to set
    
  153. :attr:`django.db.models.Options.select_on_save` flag to force saving to
    
  154. use the old algorithm.
    
  155. 
    
  156. Minor features
    
  157. --------------
    
  158. 
    
  159. * Authentication backends can raise ``PermissionDenied`` to immediately fail
    
  160.   the authentication chain.
    
  161. 
    
  162. * The ``HttpOnly`` flag can be set on the CSRF cookie with
    
  163.   :setting:`CSRF_COOKIE_HTTPONLY`.
    
  164. 
    
  165. * The :meth:`~django.test.TransactionTestCase.assertQuerysetEqual` now checks
    
  166.   for undefined order and raises :exc:`ValueError` if undefined
    
  167.   order is spotted. The order is seen as undefined if the given ``QuerySet``
    
  168.   isn't ordered and there is more than one ordered value to compare against.
    
  169. 
    
  170. * Added :meth:`~django.db.models.query.QuerySet.earliest` for symmetry with
    
  171.   :meth:`~django.db.models.query.QuerySet.latest`.
    
  172. 
    
  173. * In addition to :lookup:`year`, :lookup:`month` and :lookup:`day`, the ORM
    
  174.   now supports :lookup:`hour`, :lookup:`minute` and :lookup:`second` lookups.
    
  175. 
    
  176. * Django now wraps all :pep:`249` exceptions.
    
  177. 
    
  178. * The default widgets for :class:`~django.forms.EmailField`,
    
  179.   :class:`~django.forms.URLField`, :class:`~django.forms.IntegerField`,
    
  180.   :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` use
    
  181.   the new type attributes available in HTML5 (``type='email'``, ``type='url'``,
    
  182.   ``type='number'``). Note that due to erratic support of the ``number``
    
  183.   input type with localized numbers in current browsers, Django only uses it
    
  184.   when numeric fields are not localized.
    
  185. 
    
  186. * The ``number`` argument for :ref:`lazy plural translations
    
  187.   <lazy-plural-translations>` can be provided at translation time rather than
    
  188.   at definition time.
    
  189. 
    
  190. * For custom management commands: Verification of the presence of valid
    
  191.   settings in commands that ask for it by using the
    
  192.   ``BaseCommand.can_import_settings`` internal
    
  193.   option is now performed independently from handling of the locale that
    
  194.   should be active during the execution of the command. The latter can now be
    
  195.   influenced by the new
    
  196.   ``BaseCommand.leave_locale_alone`` internal
    
  197.   option. See :ref:`management-commands-and-locales` for more details.
    
  198. 
    
  199. * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of
    
  200.   :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with
    
  201.   its ``object``’s ``__dict__``.
    
  202. 
    
  203. * :class:`~django.http.HttpResponseRedirect` and
    
  204.   :class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
    
  205.   attribute (equivalent to the URL the response will redirect to).
    
  206. 
    
  207. * The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
    
  208.   protocol available.
    
  209. 
    
  210. * Added :class:`~django.contrib.messages.views.SuccessMessageMixin` which
    
  211.   provides a ``success_message`` attribute for
    
  212.   :class:`~django.views.generic.edit.FormView` based classes.
    
  213. 
    
  214. * Added the :attr:`django.db.models.ForeignKey.db_constraint` and
    
  215.   :attr:`django.db.models.ManyToManyField.db_constraint` options.
    
  216. 
    
  217. * The jQuery library embedded in the admin has been upgraded to version 1.9.1.
    
  218. 
    
  219. * Syndication feeds (:mod:`django.contrib.syndication`) can now pass extra
    
  220.   context through to feed templates using a new
    
  221.   :meth:`Feed.get_context_data()
    
  222.   <django.contrib.syndication.Feed.get_context_data>` callback.
    
  223. 
    
  224. * The admin list columns have a ``column-<field_name>`` class in the HTML
    
  225.   so the columns header can be styled with CSS, e.g. to set a column width.
    
  226. 
    
  227. * The :ref:`isolation level<database-isolation-level>` can be customized under
    
  228.   PostgreSQL.
    
  229. 
    
  230. * The :ttag:`blocktrans` template tag now respects
    
  231.   ``TEMPLATE_STRING_IF_INVALID`` for variables not present in the
    
  232.   context, just like other template constructs.
    
  233. 
    
  234. * ``SimpleLazyObject``\s will now present more helpful representations in shell
    
  235.   debugging situations.
    
  236. 
    
  237. * Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
    
  238.   with the OpenLayers widget in the admin.
    
  239. 
    
  240. * The documentation contains a :doc:`deployment checklist
    
  241.   </howto/deployment/checklist>`.
    
  242. 
    
  243. * The :djadmin:`diffsettings` command gained a ``--all`` option.
    
  244. 
    
  245. * ``django.forms.fields.Field.__init__`` now calls ``super()``, allowing
    
  246.   field mixins to implement ``__init__()`` methods that will reliably be
    
  247.   called.
    
  248. 
    
  249. * The ``validate_max`` parameter was added to ``BaseFormSet`` and
    
  250.   :func:`~django.forms.formsets.formset_factory`, and ``ModelForm`` and inline
    
  251.   versions of the same.  The behavior of validation for formsets with
    
  252.   ``max_num`` was clarified.  The previously undocumented behavior that
    
  253.   hardened formsets against memory exhaustion attacks was documented,
    
  254.   and the undocumented limit of the higher of 1000 or ``max_num`` forms
    
  255.   was changed so it is always 1000 more than ``max_num``.
    
  256. 
    
  257. * Added ``BCryptSHA256PasswordHasher`` to resolve the password truncation issue
    
  258.   with bcrypt.
    
  259. 
    
  260. * `Pillow`_ is now the preferred image manipulation library to use with Django.
    
  261.   `PIL`_ is pending deprecation (support to be removed in Django 1.8).
    
  262.   To upgrade, you should **first** uninstall PIL, **then** install Pillow.
    
  263. 
    
  264. .. _`Pillow`: https://pypi.org/project/Pillow/
    
  265. .. _`PIL`: https://pypi.org/project/PIL/
    
  266. 
    
  267. * :class:`~django.forms.ModelForm` accepts several new ``Meta``
    
  268.   options.
    
  269. 
    
  270.   * Fields included in the ``localized_fields`` list will be localized
    
  271.     (by setting ``localize`` on the form field).
    
  272.   * The  ``labels``, ``help_texts`` and ``error_messages`` options may be used
    
  273.     to customize the default fields, see
    
  274.     :ref:`modelforms-overriding-default-fields` for details.
    
  275. 
    
  276. * The ``choices`` argument to model fields now accepts an iterable of iterables
    
  277.   instead of requiring an iterable of lists or tuples.
    
  278. 
    
  279. * The reason phrase can be customized in HTTP responses using
    
  280.   :attr:`~django.http.HttpResponse.reason_phrase`.
    
  281. 
    
  282. * When giving the URL of the next page for
    
  283.   ``django.contrib.auth.views.logout()``,
    
  284.   ``django.contrib.auth.views.password_reset()``,
    
  285.   ``django.contrib.auth.views.password_reset_confirm()``,
    
  286.   and ``django.contrib.auth.views.password_change()``, you can now pass
    
  287.   URL names and they will be resolved.
    
  288. 
    
  289. * The new :option:`dumpdata --pks` option specifies the primary keys of objects
    
  290.   to dump. This option can only be used with one model.
    
  291. 
    
  292. * Added ``QuerySet`` methods :meth:`~django.db.models.query.QuerySet.first`
    
  293.   and :meth:`~django.db.models.query.QuerySet.last` which are convenience
    
  294.   methods returning the first or last object matching the filters. Returns
    
  295.   ``None`` if there are no objects matching.
    
  296. 
    
  297. * :class:`~django.views.generic.base.View` and
    
  298.   :class:`~django.views.generic.base.RedirectView` now support HTTP ``PATCH``
    
  299.   method.
    
  300. 
    
  301. * ``GenericForeignKey`` now takes an optional ``for_concrete_model`` argument,
    
  302.   which when set to ``False`` allows the field to reference proxy models. The
    
  303.   default is ``True`` to retain the old behavior.
    
  304. 
    
  305. * The :class:`~django.middleware.locale.LocaleMiddleware` now stores the active
    
  306.   language in session if it is not present there. This prevents loss of
    
  307.   language settings after session flush, e.g. logout.
    
  308. 
    
  309. * :exc:`~django.core.exceptions.SuspiciousOperation` has been differentiated
    
  310.   into a number of subclasses, and each will log to a matching named logger
    
  311.   under the ``django.security`` logging hierarchy. Along with this change,
    
  312.   a ``handler400`` mechanism and default view are used whenever
    
  313.   a ``SuspiciousOperation`` reaches the WSGI handler to return an
    
  314.   ``HttpResponseBadRequest``.
    
  315. 
    
  316. * The :exc:`~django.db.models.Model.DoesNotExist` exception now includes a
    
  317.   message indicating the name of the attribute used for the lookup.
    
  318. 
    
  319. * The :meth:`~django.db.models.query.QuerySet.get_or_create` method no longer
    
  320.   requires at least one keyword argument.
    
  321. 
    
  322. * The :class:`~django.test.SimpleTestCase` class includes a new assertion
    
  323.   helper for testing formset errors:
    
  324.   :meth:`~django.test.SimpleTestCase.assertFormsetError`.
    
  325. 
    
  326. * The list of related fields added to a
    
  327.   :class:`~django.db.models.query.QuerySet` by
    
  328.   :meth:`~django.db.models.query.QuerySet.select_related` can be cleared using
    
  329.   ``select_related(None)``.
    
  330. 
    
  331. * The :meth:`~django.contrib.admin.InlineModelAdmin.get_extra` and
    
  332.   :meth:`~django.contrib.admin.InlineModelAdmin.get_max_num` methods on
    
  333.   :class:`~django.contrib.admin.InlineModelAdmin` may be overridden to
    
  334.   customize the extra and maximum number of inline forms.
    
  335. 
    
  336. * Formsets now have a
    
  337.   :meth:`~django.forms.formsets.BaseFormSet.total_error_count` method.
    
  338. 
    
  339. * :class:`~django.forms.ModelForm` fields can now override error messages
    
  340.   defined in model fields by using the
    
  341.   :attr:`~django.forms.Field.error_messages` argument of a ``Field``’s
    
  342.   constructor. To take advantage of this new feature with your custom fields,
    
  343.   :ref:`see the updated recommendation <raising-validation-error>` for raising
    
  344.   a ``ValidationError``.
    
  345. 
    
  346. * :class:`~django.contrib.admin.ModelAdmin` now preserves filters on the list view
    
  347.   after creating, editing or deleting an object. It's possible to restore the previous
    
  348.   behavior of clearing filters by setting the
    
  349.   :attr:`~django.contrib.admin.ModelAdmin.preserve_filters` attribute to ``False``.
    
  350. 
    
  351. * Added
    
  352.   :meth:`FormMixin.get_prefix<django.views.generic.edit.FormMixin.get_prefix>`
    
  353.   (which returns
    
  354.   :attr:`FormMixin.prefix<django.views.generic.edit.FormMixin.prefix>` by
    
  355.   default) to allow customizing the :attr:`~django.forms.Form.prefix` of the
    
  356.   form.
    
  357. 
    
  358. * Raw queries (``Manager.raw()`` or ``cursor.execute()``) can now use the
    
  359.   "pyformat" parameter style, where placeholders in the query are given as
    
  360.   ``'%(name)s'`` and the parameters are passed as a dictionary rather than
    
  361.   a list (except on SQLite). This has long been possible (but not officially
    
  362.   supported) on MySQL and PostgreSQL, and is now also available on Oracle.
    
  363. 
    
  364. * The default iteration count for the PBKDF2 password hasher has been
    
  365.   increased by 20%. This backwards compatible change will not affect
    
  366.   existing passwords or users who have subclassed
    
  367.   ``django.contrib.auth.hashers.PBKDF2PasswordHasher`` to change the
    
  368.   default value. Passwords :ref:`will be upgraded <password-upgrades>` to use
    
  369.   the new iteration count as necessary.
    
  370. 
    
  371. .. _backwards-incompatible-1.6:
    
  372. 
    
  373. Backwards incompatible changes in 1.6
    
  374. =====================================
    
  375. 
    
  376. .. warning::
    
  377. 
    
  378.     In addition to the changes outlined in this section, be sure to review the
    
  379.     :ref:`deprecation plan <deprecation-removed-in-1.6>` for any features that
    
  380.     have been removed. If you haven't updated your code within the
    
  381.     deprecation timeline for a given feature, its removal may appear as a
    
  382.     backwards incompatible change.
    
  383. 
    
  384. New transaction management model
    
  385. --------------------------------
    
  386. 
    
  387. Behavior changes
    
  388. ~~~~~~~~~~~~~~~~
    
  389. 
    
  390. Database-level autocommit is enabled by default in Django 1.6. While this
    
  391. doesn't change the general spirit of Django's transaction management, there
    
  392. are a few backwards-incompatibilities.
    
  393. 
    
  394. Savepoints and ``assertNumQueries``
    
  395. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  396. 
    
  397. The changes in transaction management may result in additional statements to
    
  398. create, release or rollback savepoints. This is more likely to happen with
    
  399. SQLite, since it didn't support savepoints until this release.
    
  400. 
    
  401. If tests using :meth:`~django.test.TransactionTestCase.assertNumQueries` fail
    
  402. because of a higher number of queries than expected, check that the extra
    
  403. queries are related to savepoints, and adjust the expected number of queries
    
  404. accordingly.
    
  405. 
    
  406. Autocommit option for PostgreSQL
    
  407. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  408. 
    
  409. In previous versions, database-level autocommit was only an option for
    
  410. PostgreSQL, and it was disabled by default. This option is now ignored and can
    
  411. be removed.
    
  412. 
    
  413. .. _new-test-runner:
    
  414. 
    
  415. New test runner
    
  416. ---------------
    
  417. 
    
  418. In order to maintain greater consistency with Python's ``unittest`` module, the
    
  419. new test runner (``django.test.runner.DiscoverRunner``) does not automatically
    
  420. support some types of tests that were supported by the previous runner:
    
  421. 
    
  422. * Tests in ``models.py`` and ``tests/__init__.py`` files will no longer be
    
  423.   found and run. Move them to a file whose name begins with ``test``.
    
  424. 
    
  425. * Doctests will no longer be automatically discovered. To integrate doctests in
    
  426.   your test suite, follow the :ref:`recommendations in the Python documentation
    
  427.   <doctest-unittest-api>`.
    
  428. 
    
  429. Django bundles a modified version of the :mod:`doctest` module from the Python
    
  430. standard library (in ``django.test._doctest``) and includes some additional
    
  431. doctest utilities. These utilities are deprecated and will be removed in Django
    
  432. 1.8; doctest suites should be updated to work with the standard library's
    
  433. doctest module (or converted to ``unittest``-compatible tests).
    
  434. 
    
  435. If you wish to delay updates to your test suite, you can set your
    
  436. :setting:`TEST_RUNNER` setting to ``django.test.simple.DjangoTestSuiteRunner``
    
  437. to fully restore the old test behavior. ``DjangoTestSuiteRunner`` is deprecated
    
  438. but will not be removed from Django until version 1.8.
    
  439. 
    
  440. Removal of ``django.contrib.gis.tests.GeoDjangoTestSuiteRunner`` GeoDjango custom test runner
    
  441. ---------------------------------------------------------------------------------------------
    
  442. 
    
  443. This is for developers working on the GeoDjango application itself and related
    
  444. to the item above about changes in the test runners:
    
  445. 
    
  446. The ``django.contrib.gis.tests.GeoDjangoTestSuiteRunner`` test runner has been
    
  447. removed and the standalone GeoDjango tests execution setup it implemented isn't
    
  448. supported anymore. To run the GeoDjango tests simply use the new
    
  449. ``DiscoverRunner`` and specify the ``django.contrib.gis`` app.
    
  450. 
    
  451. Custom user models in tests
    
  452. ---------------------------
    
  453. 
    
  454. The introduction of the new test runner has also slightly changed the way that
    
  455. test models are imported. As a result, any test that overrides ``AUTH_USER_MODEL``
    
  456. to test behavior with one of Django's test user models (
    
  457. ``django.contrib.auth.tests.custom_user.CustomUser`` and
    
  458. ``django.contrib.auth.tests.custom_user.ExtensionUser``) must now
    
  459. explicitly import the User model in your test module::
    
  460. 
    
  461.     from django.contrib.auth.tests.custom_user import CustomUser
    
  462. 
    
  463.     @override_settings(AUTH_USER_MODEL='auth.CustomUser')
    
  464.     class CustomUserFeatureTests(TestCase):
    
  465.         def test_something(self):
    
  466.             # Test code here ...
    
  467. 
    
  468. This import forces the custom user model to be registered. Without this import,
    
  469. the test will be unable to swap in the custom user model, and you will get an
    
  470. error reporting::
    
  471. 
    
  472.     ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.CustomUser' that has not been installed
    
  473. 
    
  474. Time zone-aware ``day``, ``month``, and ``week_day`` lookups
    
  475. ------------------------------------------------------------
    
  476. 
    
  477. Django 1.6 introduces time zone support for :lookup:`day`, :lookup:`month`,
    
  478. and :lookup:`week_day` lookups when :setting:`USE_TZ` is ``True``. These
    
  479. lookups were previously performed in UTC regardless of the current time zone.
    
  480. 
    
  481. This requires :ref:`time zone definitions in the database
    
  482. <database-time-zone-definitions>`. If you're using SQLite, you must install
    
  483. pytz_. If you're using MySQL, you must install pytz_ and load the time zone
    
  484. tables with `mysql_tzinfo_to_sql`_.
    
  485. 
    
  486. .. _pytz: http://pytz.sourceforge.net/
    
  487. .. _mysql_tzinfo_to_sql: https://dev.mysql.com/doc/refman/en/mysql-tzinfo-to-sql.html
    
  488. 
    
  489. Addition of ``QuerySet.datetimes()``
    
  490. ------------------------------------
    
  491. 
    
  492. When the :doc:`time zone support </topics/i18n/timezones>` added in Django 1.4
    
  493. was active, :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>`
    
  494. lookups returned unexpected results, because the aggregation was performed in
    
  495. UTC. To fix this, Django 1.6 introduces a new API, :meth:`QuerySet.datetimes()
    
  496. <django.db.models.query.QuerySet.datetimes>`. This requires a few changes in
    
  497. your code.
    
  498. 
    
  499. ``QuerySet.dates()`` returns ``date`` objects
    
  500. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  501. 
    
  502. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` now returns a
    
  503. list of :class:`~datetime.date`. It used to return a list of
    
  504. :class:`~datetime.datetime`.
    
  505. 
    
  506. :meth:`QuerySet.datetimes() <django.db.models.query.QuerySet.datetimes>`
    
  507. returns a list of :class:`~datetime.datetime`.
    
  508. 
    
  509. ``QuerySet.dates()`` no longer usable on ``DateTimeField``
    
  510. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  511. 
    
  512. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` raises an
    
  513. error if it's used on :class:`~django.db.models.DateTimeField` when time
    
  514. zone support is active. Use :meth:`QuerySet.datetimes()
    
  515. <django.db.models.query.QuerySet.datetimes>` instead.
    
  516. 
    
  517. ``date_hierarchy`` requires time zone definitions
    
  518. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  519. 
    
  520. The :attr:`~django.contrib.admin.ModelAdmin.date_hierarchy` feature of the
    
  521. admin now relies on :meth:`QuerySet.datetimes()
    
  522. <django.db.models.query.QuerySet.datetimes>` when it's used on a
    
  523. :class:`~django.db.models.DateTimeField`.
    
  524. 
    
  525. This requires time zone definitions in the database when :setting:`USE_TZ` is
    
  526. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
    
  527. 
    
  528. ``date_list`` in generic views requires time zone definitions
    
  529. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  530. 
    
  531. For the same reason, accessing ``date_list`` in the context of a date-based
    
  532. generic view requires time zone definitions in the database when the view is
    
  533. based on a :class:`~django.db.models.DateTimeField` and :setting:`USE_TZ` is
    
  534. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
    
  535. 
    
  536. New lookups may clash with model fields
    
  537. ---------------------------------------
    
  538. 
    
  539. Django 1.6 introduces ``hour``, ``minute``, and ``second`` lookups on
    
  540. :class:`~django.db.models.DateTimeField`. If you had model fields called
    
  541. ``hour``, ``minute``, or ``second``, the new lookups will clash with you field
    
  542. names. Append an explicit :lookup:`exact` lookup if this is an issue.
    
  543. 
    
  544. ``BooleanField`` no longer defaults to ``False``
    
  545. ------------------------------------------------
    
  546. 
    
  547. When a :class:`~django.db.models.BooleanField` doesn't have an explicit
    
  548. :attr:`~django.db.models.Field.default`, the implicit default value is
    
  549. ``None``. In previous version of Django, it was ``False``, but that didn't
    
  550. represent accurately the lack of a value.
    
  551. 
    
  552. Code that relies on the default value being ``False`` may raise an exception
    
  553. when saving new model instances to the database, because ``None`` isn't an
    
  554. acceptable value for a :class:`~django.db.models.BooleanField`. You should
    
  555. either specify ``default=False`` in the field definition, or ensure the field
    
  556. is set to ``True`` or ``False`` before saving the object.
    
  557. 
    
  558. Translations and comments in templates
    
  559. --------------------------------------
    
  560. 
    
  561. Extraction of translations after comments
    
  562. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  563. 
    
  564. Extraction of translatable literals from templates with the
    
  565. :djadmin:`makemessages` command now correctly detects i18n constructs when
    
  566. they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
    
  567. 
    
  568. .. code-block:: html+django
    
  569. 
    
  570.     {# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
    
  571. 
    
  572. Location of translator comments
    
  573. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  574. 
    
  575. :ref:`translator-comments-in-templates` specified using ``{#`` / ``#}`` need to
    
  576. be at the end of a line. If they are not, the comments are ignored and
    
  577. :djadmin:`makemessages` will generate a warning. For example:
    
  578. 
    
  579. .. code-block:: html+django
    
  580. 
    
  581.     {# Translators: This is ignored #}{% trans "Translate me" %}
    
  582.     {{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
    
  583.     <h1>{% trans "Welcome" %}</h1>
    
  584. 
    
  585. Quoting in ``reverse()``
    
  586. ------------------------
    
  587. 
    
  588. When reversing URLs, Django didn't apply ``django.utils.http.urlquote``
    
  589. to arguments before interpolating them in URL patterns. This bug is fixed in
    
  590. Django 1.6. If you worked around this bug by applying URL quoting before
    
  591. passing arguments to ``reverse()``, this may result in double-quoting. If this
    
  592. happens, simply remove the URL quoting from your code. You will also have to
    
  593. replace special characters in URLs used in
    
  594. :func:`~django.test.SimpleTestCase.assertRedirects` with their encoded
    
  595. versions.
    
  596. 
    
  597. Storage of IP addresses in the comments app
    
  598. -------------------------------------------
    
  599. 
    
  600. The comments app now uses a
    
  601. ``GenericIPAddressField`` for storing commenters' IP addresses, to support
    
  602. comments submitted from IPv6 addresses. Until now, it stored them in an
    
  603. ``IPAddressField``, which is only meant to support IPv4. When saving a comment
    
  604. made from an IPv6 address, the address would be silently truncated on MySQL
    
  605. databases, and raise an exception on Oracle. You will need to change the
    
  606. column type in your database to benefit from this change.
    
  607. 
    
  608. For MySQL, execute this query on your project's database:
    
  609. 
    
  610. .. code-block:: sql
    
  611. 
    
  612.     ALTER TABLE django_comments MODIFY ip_address VARCHAR(39);
    
  613. 
    
  614. For Oracle, execute this query:
    
  615. 
    
  616. .. code-block:: sql
    
  617. 
    
  618.     ALTER TABLE DJANGO_COMMENTS MODIFY (ip_address VARCHAR2(39));
    
  619. 
    
  620. If you do not apply this change, the behavior is unchanged: on MySQL, IPv6
    
  621. addresses are silently truncated; on Oracle, an exception is generated. No
    
  622. database change is needed for SQLite or PostgreSQL databases.
    
  623. 
    
  624. Percent literals in ``cursor.execute`` queries
    
  625. ----------------------------------------------
    
  626. 
    
  627. When you are running raw SQL queries through the
    
  628. :ref:`cursor.execute <executing-custom-sql>` method, the rule about doubling
    
  629. percent literals (``%``) inside the query has been unified. Past behavior
    
  630. depended on the database backend. Now, across all backends, you only need to
    
  631. double literal percent characters if you are also providing replacement
    
  632. parameters. For example::
    
  633. 
    
  634.     # No parameters, no percent doubling
    
  635.     cursor.execute("SELECT foo FROM bar WHERE baz = '30%'")
    
  636. 
    
  637.     # Parameters passed, non-placeholders have to be doubled
    
  638.     cursor.execute("SELECT foo FROM bar WHERE baz = '30%%' and id = %s", [self.id])
    
  639. 
    
  640. ``SQLite`` users need to check and update such queries.
    
  641. 
    
  642. .. _m2m-help_text:
    
  643. 
    
  644. Help text of model form fields for ManyToManyField fields
    
  645. ---------------------------------------------------------
    
  646. 
    
  647. HTML rendering of model form fields corresponding to
    
  648. :class:`~django.db.models.ManyToManyField` model fields used to get the
    
  649. hard-coded sentence:
    
  650. 
    
  651.   *Hold down "Control", or "Command" on a Mac, to select more than one.*
    
  652. 
    
  653. (or its translation to the active locale) imposed as the help legend shown along
    
  654. them if neither :attr:`model <django.db.models.Field.help_text>` nor :attr:`form
    
  655. <django.forms.Field.help_text>` ``help_text`` attributes were specified by the
    
  656. user (or this string was appended to any ``help_text`` that was provided).
    
  657. 
    
  658. Since this happened at the model layer, there was no way to prevent the text
    
  659. from appearing in cases where it wasn't applicable such as form fields that
    
  660. implement user interactions that don't involve a keyboard and/or a mouse.
    
  661. 
    
  662. Starting with Django 1.6, as an ad-hoc temporary backward-compatibility
    
  663. provision, the logic to add the "Hold down..." sentence has been moved to the
    
  664. model form field layer and modified to add the text only when the associated
    
  665. widget is :class:`~django.forms.SelectMultiple` or selected subclasses.
    
  666. 
    
  667. The change can affect you in a backward incompatible way if you employ custom
    
  668. model form fields and/or widgets for ``ManyToManyField`` model fields whose UIs
    
  669. do rely on the automatic provision of the mentioned hard-coded sentence. These
    
  670. form field implementations need to adapt to the new scenario by providing their
    
  671. own handling of the ``help_text`` attribute.
    
  672. 
    
  673. Applications that use Django :doc:`model form </topics/forms/modelforms>`
    
  674. facilities together with Django built-in form :doc:`fields </ref/forms/fields>`
    
  675. and :doc:`widgets </ref/forms/widgets>` aren't affected but need to be aware of
    
  676. what's described in :ref:`m2m-help_text-deprecation` below.
    
  677. 
    
  678. QuerySet iteration
    
  679. ------------------
    
  680. 
    
  681. The ``QuerySet`` iteration was changed to immediately convert all fetched
    
  682. rows to ``Model`` objects. In Django 1.5 and earlier the fetched rows were
    
  683. converted to ``Model`` objects in chunks of 100.
    
  684. 
    
  685. Existing code will work, but the amount of rows converted to objects
    
  686. might change in certain use cases. Such usages include partially looping
    
  687. over a queryset or any usage which ends up doing ``__bool__`` or
    
  688. ``__contains__``.
    
  689. 
    
  690. Notably most database backends did fetch all the rows in one go already in
    
  691. 1.5.
    
  692. 
    
  693. It is still possible to convert the fetched rows to ``Model`` objects
    
  694. lazily by using the :meth:`~django.db.models.query.QuerySet.iterator()`
    
  695. method.
    
  696. 
    
  697. :meth:`BoundField.label_tag<django.forms.BoundField.label_tag>` now includes the form's :attr:`~django.forms.Form.label_suffix`
    
  698. -------------------------------------------------------------------------------------------------------------------------------
    
  699. 
    
  700. This is consistent with how methods like
    
  701. :meth:`Form.as_p<django.forms.Form.as_p>` and
    
  702. :meth:`Form.as_ul<django.forms.Form.as_ul>` render labels.
    
  703. 
    
  704. If you manually render ``label_tag`` in your templates:
    
  705. 
    
  706. .. code-block:: html+django
    
  707. 
    
  708.     {{ form.my_field.label_tag }}: {{ form.my_field }}
    
  709. 
    
  710. you'll want to remove the colon (or whatever other separator you may be
    
  711. using) to avoid duplicating it when upgrading to Django 1.6. The following
    
  712. template in Django 1.6 will render identically to the above template in Django
    
  713. 1.5, except that the colon will appear inside the ``<label>`` element.
    
  714. 
    
  715. .. code-block:: html+django
    
  716. 
    
  717.      {{ form.my_field.label_tag }} {{ form.my_field }}
    
  718. 
    
  719. will render something like:
    
  720. 
    
  721. .. code-block:: html
    
  722. 
    
  723.     <label for="id_my_field">My Field:</label> <input id="id_my_field" type="text" name="my_field" />
    
  724. 
    
  725. If you want to keep the current behavior of rendering ``label_tag`` without
    
  726. the ``label_suffix``, instantiate the form ``label_suffix=''``. You can also
    
  727. customize the ``label_suffix`` on a per-field basis using the new
    
  728. ``label_suffix`` parameter on :meth:`~django.forms.BoundField.label_tag`.
    
  729. 
    
  730. Admin views ``_changelist_filters`` GET parameter
    
  731. -------------------------------------------------
    
  732. 
    
  733. To achieve preserving and restoring list view filters, admin views now
    
  734. pass around the ``_changelist_filters`` GET parameter. It's important that you
    
  735. account for that change if you have custom admin templates or if your tests
    
  736. rely on the previous URLs. If you want to revert to the original behavior you
    
  737. can set the
    
  738. :attr:`~django.contrib.admin.ModelAdmin.preserve_filters` attribute to ``False``.
    
  739. 
    
  740. ``django.contrib.auth`` password reset uses base 64 encoding of ``User`` PK
    
  741. ---------------------------------------------------------------------------
    
  742. 
    
  743. Past versions of Django used base 36 encoding of the ``User`` primary key in
    
  744. the password reset views and URLs
    
  745. (``django.contrib.auth.views.password_reset_confirm()``). Base 36 encoding is
    
  746. sufficient if the user primary key is an integer, however, with the
    
  747. introduction of custom user models in Django 1.5, that assumption may no longer
    
  748. be true.
    
  749. 
    
  750. ``django.contrib.auth.views.password_reset_confirm()`` has been modified to
    
  751. take a ``uidb64`` parameter instead of ``uidb36``. If you are reversing this
    
  752. view, for example in a custom ``password_reset_email.html`` template, be sure
    
  753. to update your code.
    
  754. 
    
  755. A temporary shim for ``django.contrib.auth.views.password_reset_confirm()``
    
  756. that will allow password reset links generated prior to Django 1.6 to continue
    
  757. to work has been added to provide backwards compatibility; this will be removed
    
  758. in Django 1.7. Thus, as long as your site has been running Django 1.6 for more
    
  759. than ``PASSWORD_RESET_TIMEOUT_DAYS``, this change will have no effect.
    
  760. If not (for example, if you upgrade directly from Django 1.5 to Django 1.7),
    
  761. then any password reset links generated before you upgrade to Django 1.7 or
    
  762. later won't work after the upgrade.
    
  763. 
    
  764. In addition, if you have any custom password reset URLs, you will need to
    
  765. update them by replacing ``uidb36`` with ``uidb64`` and the dash that follows
    
  766. that pattern with a slash. Also add ``_\-`` to the list of characters that may
    
  767. match the ``uidb64`` pattern.
    
  768. 
    
  769. For example::
    
  770. 
    
  771.     url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
    
  772.         'django.contrib.auth.views.password_reset_confirm',
    
  773.         name='password_reset_confirm'),
    
  774. 
    
  775. becomes::
    
  776. 
    
  777.     url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
    
  778.         'django.contrib.auth.views.password_reset_confirm',
    
  779.         name='password_reset_confirm'),
    
  780. 
    
  781. You may also want to add the shim to support the old style reset links. Using
    
  782. the example above, you would modify the existing url by replacing
    
  783. ``django.contrib.auth.views.password_reset_confirm`` with
    
  784. ``django.contrib.auth.views.password_reset_confirm_uidb36`` and also remove
    
  785. the ``name`` argument so it doesn't conflict with the new url::
    
  786. 
    
  787.     url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
    
  788.         'django.contrib.auth.views.password_reset_confirm_uidb36'),
    
  789. 
    
  790. You can remove this URL pattern after your app has been deployed with Django
    
  791. 1.6 for ``PASSWORD_RESET_TIMEOUT_DAYS``.
    
  792. 
    
  793. Default session serialization switched to JSON
    
  794. ----------------------------------------------
    
  795. 
    
  796. Historically, :mod:`django.contrib.sessions` used :mod:`pickle` to serialize
    
  797. session data before storing it in the backend. If you're using the :ref:`signed
    
  798. cookie session backend<cookie-session-backend>` and :setting:`SECRET_KEY` is
    
  799. known by an attacker (there isn't an inherent vulnerability in Django that
    
  800. would cause it to leak), the attacker could insert a string into their session
    
  801. which, when unpickled, executes arbitrary code on the server. The technique for
    
  802. doing so is simple and easily available on the internet. Although the cookie
    
  803. session storage signs the cookie-stored data to prevent tampering, a
    
  804. :setting:`SECRET_KEY` leak immediately escalates to a remote code execution
    
  805. vulnerability.
    
  806. 
    
  807. This attack can be mitigated by serializing session data using JSON rather
    
  808. than :mod:`pickle`. To facilitate this, Django 1.5.3 introduced a new setting,
    
  809. :setting:`SESSION_SERIALIZER`, to customize the session serialization format.
    
  810. For backwards compatibility, this setting defaulted to using :mod:`pickle`
    
  811. in Django 1.5.3, but we've changed the default to JSON in 1.6. If you upgrade
    
  812. and switch from pickle to JSON, sessions created before the upgrade will be
    
  813. lost. While JSON serialization does not support all Python objects like
    
  814. :mod:`pickle` does, we highly recommend using JSON-serialized sessions. Be
    
  815. aware of the following when checking your code to determine if JSON
    
  816. serialization will work for your application:
    
  817. 
    
  818. * JSON requires string keys, so you will likely run into problems if you are
    
  819.   using non-string keys in ``request.session``.
    
  820. * Setting session expiration by passing ``datetime`` values to
    
  821.   :meth:`~django.contrib.sessions.backends.base.SessionBase.set_expiry` will
    
  822.   not work as ``datetime`` values are not serializable in JSON. You can use
    
  823.   integer values instead.
    
  824. 
    
  825. See the :ref:`session_serialization` documentation for more details.
    
  826. 
    
  827. Object Relational Mapper changes
    
  828. --------------------------------
    
  829. 
    
  830. Django 1.6 contains many changes to the ORM. These changes fall mostly in
    
  831. three categories:
    
  832. 
    
  833. 1. Bug fixes (e.g. proper join clauses for generic relations, query combining,
    
  834.    join promotion, and join trimming fixes)
    
  835. 2. Preparation for new features. For example the ORM is now internally ready
    
  836.    for multicolumn foreign keys.
    
  837. 3. General cleanup.
    
  838. 
    
  839. These changes can result in some compatibility problems. For example, some
    
  840. queries will now generate different table aliases. This can affect
    
  841. :meth:`QuerySet.extra() <django.db.models.query.QuerySet.extra>`. In addition
    
  842. some queries will now produce different results. An example is
    
  843. :meth:`exclude(condition) <django.db.models.query.QuerySet.exclude>`
    
  844. where the condition is a complex one (referencing multijoins inside
    
  845. :class:`Q objects <django.db.models.Q>`). In many cases the affected
    
  846. queries didn't produce correct results in Django 1.5 but do now.
    
  847. Unfortunately there are also cases that produce different results, but
    
  848. neither Django 1.5 nor 1.6 produce correct results.
    
  849. 
    
  850. Finally, there have been many changes to the ORM internal APIs.
    
  851. 
    
  852. Miscellaneous
    
  853. -------------
    
  854. 
    
  855. * The ``django.db.models.query.EmptyQuerySet`` can't be instantiated any more -
    
  856.   it is only usable as a marker class for checking if
    
  857.   :meth:`~django.db.models.query.QuerySet.none` has been called:
    
  858.   ``isinstance(qs.none(), EmptyQuerySet)``
    
  859. 
    
  860. * If your CSS/JavaScript code used to access HTML input widgets by type, you
    
  861.   should review it as ``type='text'`` widgets might be now output as
    
  862.   ``type='email'``, ``type='url'`` or ``type='number'`` depending on their
    
  863.   corresponding field type.
    
  864. 
    
  865. * Form field's :attr:`~django.forms.Field.error_messages` that contain a
    
  866.   placeholder should now always use a named placeholder (``"Value '%(value)s' is
    
  867.   too big"`` instead of ``"Value '%s' is too big"``). See the corresponding
    
  868.   field documentation for details about the names of the placeholders. The
    
  869.   changes in 1.6 particularly affect :class:`~django.forms.DecimalField` and
    
  870.   :class:`~django.forms.ModelMultipleChoiceField`.
    
  871. 
    
  872. * Some :attr:`~django.forms.Field.error_messages` for
    
  873.   :class:`~django.forms.IntegerField`, :class:`~django.forms.EmailField`,
    
  874.   ``IPAddressField``, :class:`~django.forms.GenericIPAddressField`, and
    
  875.   :class:`~django.forms.SlugField` have been suppressed because they
    
  876.   duplicated error messages already provided by validators tied to the fields.
    
  877. 
    
  878. * Due to a change in the form validation workflow,
    
  879.   :class:`~django.forms.TypedChoiceField` ``coerce`` method should always
    
  880.   return a value present in the ``choices`` field attribute. That limitation
    
  881.   should be lift again in Django 1.7.
    
  882. 
    
  883. * There have been changes in the way timeouts are handled in cache backends.
    
  884.   Explicitly passing in ``timeout=None`` no longer results in using the
    
  885.   default timeout. It will now set a non-expiring timeout. Passing 0 into the
    
  886.   memcache backend no longer uses the default timeout, and now will
    
  887.   set-and-expire-immediately the value.
    
  888. 
    
  889. * The ``django.contrib.flatpages`` app used to set custom HTTP headers for
    
  890.   debugging purposes. This functionality was not documented and made caching
    
  891.   ineffective so it has been removed, along with its generic implementation,
    
  892.   previously available in ``django.core.xheaders``.
    
  893. 
    
  894. * The ``XViewMiddleware`` has been moved from ``django.middleware.doc`` to
    
  895.   ``django.contrib.admindocs.middleware`` because it is an implementation
    
  896.   detail of admindocs, proven not to be reusable in general.
    
  897. 
    
  898. * :class:`~django.db.models.GenericIPAddressField` will now only allow
    
  899.   ``blank`` values if ``null`` values are also allowed. Creating a
    
  900.   ``GenericIPAddressField`` where ``blank`` is allowed but ``null`` is not
    
  901.   will trigger a model validation error because ``blank`` values are always
    
  902.   stored as ``null``. Previously, storing a ``blank`` value in a field which
    
  903.   did not allow ``null`` would cause a database exception at runtime.
    
  904. 
    
  905. * If a ``NoReverseMatch`` exception is raised from a method when rendering a
    
  906.   template, it is not silenced. For example, ``{{ obj.view_href }}`` will
    
  907.   cause template rendering to fail if ``view_href()`` raises
    
  908.   ``NoReverseMatch``. There is no change to the :ttag:`{% url %}<url>` tag, it
    
  909.   causes template rendering to fail like always when ``NoReverseMatch`` is
    
  910.   raised.
    
  911. 
    
  912. * :meth:`django.test.Client.logout` now calls
    
  913.   :meth:`django.contrib.auth.logout` which will send the
    
  914.   :func:`~django.contrib.auth.signals.user_logged_out` signal.
    
  915. 
    
  916. * :ref:`Authentication views <built-in-auth-views>` are now reversed by name,
    
  917.   not their locations in ``django.contrib.auth.views``. If you are using the
    
  918.   views without a ``name``, you should update your ``urlpatterns`` to use
    
  919.   ``django.conf.urls.url()`` with the ``name`` parameter. For example::
    
  920. 
    
  921.     (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete')
    
  922. 
    
  923.   becomes::
    
  924. 
    
  925.     url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete')
    
  926. 
    
  927. * :class:`~django.views.generic.base.RedirectView` now has a ``pattern_name``
    
  928.   attribute which allows it to choose the target by reversing the URL.
    
  929. 
    
  930. * In Django 1.4 and 1.5, a blank string was unintentionally not considered to
    
  931.   be a valid password. This meant
    
  932.   :meth:`~django.contrib.auth.models.User.set_password()` would save a blank
    
  933.   password as an unusable password like
    
  934.   :meth:`~django.contrib.auth.models.User.set_unusable_password()` does, and
    
  935.   thus :meth:`~django.contrib.auth.models.User.check_password()` always
    
  936.   returned ``False`` for blank passwords. This has been corrected in this
    
  937.   release: blank passwords are now valid.
    
  938. 
    
  939. * The admin :attr:`~django.contrib.admin.ModelAdmin.changelist_view` previously
    
  940.   accepted a ``pop`` GET parameter to signify it was to be displayed in a popup.
    
  941.   This parameter has been renamed to ``_popup`` to be consistent with the rest
    
  942.   of the admin views. You should update your custom templates if they use the
    
  943.   previous parameter name.
    
  944. 
    
  945. * :meth:`~django.core.validators.validate_email` now accepts email addresses
    
  946.   with ``localhost`` as the domain.
    
  947. 
    
  948. * The new :option:`makemessages --keep-pot` option prevents deleting the
    
  949.   temporary ``.pot`` file generated before creating the ``.po`` file.
    
  950. 
    
  951. * The undocumented ``django.core.servers.basehttp.WSGIServerException`` has
    
  952.   been removed. Use ``socket.error`` provided by the standard library instead.
    
  953.   This change was also released in Django 1.5.5.
    
  954. 
    
  955. * The signature of :meth:`django.views.generic.base.RedirectView.get_redirect_url`
    
  956.   has changed and now accepts positional arguments as well (``*args, **kwargs``).
    
  957.   Any unnamed captured group will now be passed to ``get_redirect_url()``
    
  958.   which may result in a ``TypeError`` if you don't update the signature of your
    
  959.   custom method.
    
  960. 
    
  961. .. _deprecated-features-1.6:
    
  962. 
    
  963. Features deprecated in 1.6
    
  964. ==========================
    
  965. 
    
  966. Transaction management APIs
    
  967. ---------------------------
    
  968. 
    
  969. Transaction management was completely overhauled in Django 1.6, and the
    
  970. current APIs are deprecated:
    
  971. 
    
  972. - ``django.middleware.transaction.TransactionMiddleware``
    
  973. - ``django.db.transaction.autocommit``
    
  974. - ``django.db.transaction.commit_on_success``
    
  975. - ``django.db.transaction.commit_manually``
    
  976. - the ``TRANSACTIONS_MANAGED`` setting
    
  977. 
    
  978. ``django.contrib.comments``
    
  979. ---------------------------
    
  980. 
    
  981. Django's comment framework has been deprecated and is no longer supported. It
    
  982. will be available in Django 1.6 and 1.7, and removed in Django 1.8. Most users
    
  983. will be better served with a custom solution, or a hosted product like Disqus__.
    
  984. 
    
  985. The code formerly known as ``django.contrib.comments`` is `still available
    
  986. in an external repository`__.
    
  987. 
    
  988. __ https://disqus.com/
    
  989. __ https://github.com/django/django-contrib-comments
    
  990. 
    
  991. Support for PostgreSQL versions older than 8.4
    
  992. ----------------------------------------------
    
  993. 
    
  994. The end of upstream support periods was reached in December 2011 for
    
  995. PostgreSQL 8.2 and in February 2013 for 8.3. As a consequence, Django 1.6 sets
    
  996. 8.4 as the minimum PostgreSQL version it officially supports.
    
  997. 
    
  998. You're strongly encouraged to use the most recent version of PostgreSQL
    
  999. available, because of performance improvements and to take advantage of the
    
  1000. native streaming replication available in PostgreSQL 9.x.
    
  1001. 
    
  1002. Changes to :ttag:`cycle` and :ttag:`firstof`
    
  1003. --------------------------------------------
    
  1004. 
    
  1005. The template system generally escapes all variables to avoid XSS attacks.
    
  1006. However, due to an accident of history, the :ttag:`cycle` and :ttag:`firstof`
    
  1007. tags render their arguments as-is.
    
  1008. 
    
  1009. Django 1.6 starts a process to correct this inconsistency. The ``future``
    
  1010. template library provides alternate implementations of :ttag:`cycle` and
    
  1011. :ttag:`firstof` that autoescape their inputs. If you're using these tags,
    
  1012. you're encouraged to include the following line at the top of your templates to
    
  1013. enable the new behavior::
    
  1014. 
    
  1015.     {% load cycle from future %}
    
  1016. 
    
  1017. or::
    
  1018. 
    
  1019.     {% load firstof from future %}
    
  1020. 
    
  1021. The tags implementing the old behavior have been deprecated, and in Django
    
  1022. 1.8, the old behavior will be replaced with the new behavior. To ensure
    
  1023. compatibility with future versions of Django, existing templates should be
    
  1024. modified to use the ``future`` versions.
    
  1025. 
    
  1026. If necessary, you can temporarily disable auto-escaping with
    
  1027. :func:`~django.utils.safestring.mark_safe` or :ttag:`{% autoescape off %}
    
  1028. <autoescape>`.
    
  1029. 
    
  1030. ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting
    
  1031. -------------------------------------------
    
  1032. 
    
  1033. ``CacheMiddleware`` and ``UpdateCacheMiddleware`` used to provide a way to
    
  1034. cache requests only if they weren't made by a logged-in user. This mechanism
    
  1035. was largely ineffective because the middleware correctly takes into account the
    
  1036. ``Vary: Cookie`` HTTP header, and this header is being set on a variety of
    
  1037. occasions, such as:
    
  1038. 
    
  1039. * accessing the session, or
    
  1040. * using CSRF protection, which is turned on by default, or
    
  1041. * using a client-side library which sets cookies, like `Google Analytics`__.
    
  1042. 
    
  1043. This makes the cache effectively work on a per-session basis regardless of the
    
  1044. ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting.
    
  1045. 
    
  1046. __ https://marketingplatform.google.com/about/analytics/
    
  1047. 
    
  1048. ``SEND_BROKEN_LINK_EMAILS`` setting
    
  1049. -----------------------------------
    
  1050. 
    
  1051. :class:`~django.middleware.common.CommonMiddleware` used to provide basic
    
  1052. reporting of broken links by email when ``SEND_BROKEN_LINK_EMAILS`` is set to
    
  1053. ``True``.
    
  1054. 
    
  1055. Because of intractable ordering problems between
    
  1056. :class:`~django.middleware.common.CommonMiddleware` and
    
  1057. :class:`~django.middleware.locale.LocaleMiddleware`, this feature was split
    
  1058. out into a new middleware:
    
  1059. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware`.
    
  1060. 
    
  1061. If you're relying on this feature, you should add
    
  1062. ``'django.middleware.common.BrokenLinkEmailsMiddleware'`` to your
    
  1063. ``MIDDLEWARE_CLASSES`` setting and remove ``SEND_BROKEN_LINK_EMAILS``
    
  1064. from your settings.
    
  1065. 
    
  1066. ``_has_changed`` method on widgets
    
  1067. ----------------------------------
    
  1068. 
    
  1069. If you defined your own form widgets and defined the ``_has_changed`` method
    
  1070. on a widget, you should now define this method on the form field itself.
    
  1071. 
    
  1072. ``module_name`` model _meta attribute
    
  1073. -------------------------------------
    
  1074. 
    
  1075. ``Model._meta.module_name`` was renamed to ``model_name``. Despite being a
    
  1076. private API, it will go through a regular deprecation path.
    
  1077. 
    
  1078. ``get_(add|change|delete)_permission`` model _meta methods
    
  1079. ----------------------------------------------------------
    
  1080. 
    
  1081. ``Model._meta.get_(add|change|delete)_permission`` methods were deprecated.
    
  1082. Even if they were not part of the public API they'll also go through
    
  1083. a regular deprecation path. You can replace them with
    
  1084. ``django.contrib.auth.get_permission_codename('action', Model._meta)`` where
    
  1085. ``'action'`` is ``'add'``, ``'change'``, or ``'delete'``.
    
  1086. 
    
  1087. ``get_query_set`` and similar methods renamed to ``get_queryset``
    
  1088. -----------------------------------------------------------------
    
  1089. 
    
  1090. Methods that return a ``QuerySet`` such as ``Manager.get_query_set`` or
    
  1091. ``ModelAdmin.queryset`` have been renamed to ``get_queryset``.
    
  1092. 
    
  1093. If you are writing a library that implements, for example, a
    
  1094. ``Manager.get_query_set`` method, and you need to support old Django versions,
    
  1095. you should rename the method and conditionally add an alias with the old name::
    
  1096. 
    
  1097.     class CustomManager(models.Manager):
    
  1098.         def get_queryset(self):
    
  1099.             pass # ...
    
  1100. 
    
  1101.         if django.VERSION < (1, 6):
    
  1102.             get_query_set = get_queryset
    
  1103. 
    
  1104.         # For Django >= 1.6, models.Manager provides a get_query_set fallback
    
  1105.         # that emits a warning when used.
    
  1106. 
    
  1107. If you are writing a library that needs to call the ``get_queryset`` method and
    
  1108. must support old Django versions, you should write::
    
  1109. 
    
  1110.     get_queryset = (some_manager.get_query_set
    
  1111.                     if hasattr(some_manager, 'get_query_set')
    
  1112.                     else some_manager.get_queryset)
    
  1113.     return get_queryset() # etc
    
  1114. 
    
  1115. In the general case of a custom manager that both implements its own
    
  1116. ``get_queryset`` method and calls that method, and needs to work with older Django
    
  1117. versions, and libraries that have not been updated yet, it is useful to define
    
  1118. a ``get_queryset_compat`` method as below and use it internally to your manager::
    
  1119. 
    
  1120.     class YourCustomManager(models.Manager):
    
  1121.         def get_queryset(self):
    
  1122.             return YourCustomQuerySet() # for example
    
  1123. 
    
  1124.         if django.VERSION < (1, 6):
    
  1125.             get_query_set = get_queryset
    
  1126. 
    
  1127.         def active(self): # for example
    
  1128.             return self.get_queryset_compat().filter(active=True)
    
  1129. 
    
  1130.         def get_queryset_compat(self):
    
  1131.             get_queryset = (self.get_query_set
    
  1132.                             if hasattr(self, 'get_query_set')
    
  1133.                             else self.get_queryset)
    
  1134.             return get_queryset()
    
  1135. 
    
  1136. This helps to minimize the changes that are needed, but also works correctly in
    
  1137. the case of subclasses (such as ``RelatedManagers`` from Django 1.5) which might
    
  1138. override either ``get_query_set`` or ``get_queryset``.
    
  1139. 
    
  1140. 
    
  1141. ``shortcut`` view and URLconf
    
  1142. -----------------------------
    
  1143. 
    
  1144. The ``shortcut`` view was moved from ``django.views.defaults`` to
    
  1145. ``django.contrib.contenttypes.views`` shortly after the 1.0 release, but the
    
  1146. old location was never deprecated. This oversight was corrected in Django 1.6
    
  1147. and you should now use the new location.
    
  1148. 
    
  1149. The URLconf ``django.conf.urls.shortcut`` was also deprecated. If you're
    
  1150. including it in an URLconf, simply replace::
    
  1151. 
    
  1152.     (r'^prefix/', include('django.conf.urls.shortcut')),
    
  1153. 
    
  1154. with::
    
  1155. 
    
  1156.     (r'^prefix/(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'django.contrib.contenttypes.views.shortcut'),
    
  1157. 
    
  1158. ``ModelForm`` without ``fields`` or ``exclude``
    
  1159. -----------------------------------------------
    
  1160. 
    
  1161. Previously, if you wanted a :class:`~django.forms.ModelForm` to use all fields on
    
  1162. the model, you could simply omit the ``Meta.fields`` attribute, and all fields
    
  1163. would be used.
    
  1164. 
    
  1165. This can lead to security problems where fields are added to the model and,
    
  1166. unintentionally, automatically become editable by end users. In some cases,
    
  1167. particular with boolean fields, it is possible for this problem to be completely
    
  1168. invisible. This is a form of `Mass assignment vulnerability
    
  1169. <https://en.wikipedia.org/wiki/Mass_assignment_vulnerability>`_.
    
  1170. 
    
  1171. For this reason, this behavior is deprecated, and using the ``Meta.exclude``
    
  1172. option is strongly discouraged. Instead, all fields that are intended for
    
  1173. inclusion in the form should be listed explicitly in the ``fields`` attribute.
    
  1174. 
    
  1175. If this security concern really does not apply in your case, there is a shortcut
    
  1176. to explicitly indicate that all fields should be used - use the special value
    
  1177. ``"__all__"`` for the fields attribute::
    
  1178. 
    
  1179.     class MyModelForm(ModelForm):
    
  1180.         class Meta:
    
  1181.             fields = "__all__"
    
  1182.             model = MyModel
    
  1183. 
    
  1184. If you have custom ``ModelForms`` that only need to be used in the admin, there
    
  1185. is another option. The admin has its own methods for defining fields
    
  1186. (``fieldsets`` etc.), and so adding a list of fields to the ``ModelForm`` is
    
  1187. redundant. Instead, simply omit the ``Meta`` inner class of the ``ModelForm``,
    
  1188. or omit the ``Meta.model`` attribute. Since the ``ModelAdmin`` subclass knows
    
  1189. which model it is for, it can add the necessary attributes to derive a
    
  1190. functioning ``ModelForm``. This behavior also works for earlier Django
    
  1191. versions.
    
  1192. 
    
  1193. ``UpdateView`` and ``CreateView`` without explicit fields
    
  1194. ---------------------------------------------------------
    
  1195. 
    
  1196. The generic views :class:`~django.views.generic.edit.CreateView` and
    
  1197. :class:`~django.views.generic.edit.UpdateView`, and anything else derived from
    
  1198. :class:`~django.views.generic.edit.ModelFormMixin`, are vulnerable to the
    
  1199. security problem described in the section above, because they can automatically
    
  1200. create a ``ModelForm`` that uses all fields for a model.
    
  1201. 
    
  1202. For this reason, if you use these views for editing models, you must also supply
    
  1203. the ``fields`` attribute (new in Django 1.6), which is a list of model fields
    
  1204. and works in the same way as the :class:`~django.forms.ModelForm`
    
  1205. ``Meta.fields`` attribute. Alternatively, you can set the ``form_class``
    
  1206. attribute to a ``ModelForm`` that explicitly defines the fields to be used.
    
  1207. Defining an ``UpdateView`` or ``CreateView`` subclass to be used with a model
    
  1208. but without an explicit list of fields is deprecated.
    
  1209. 
    
  1210. .. _m2m-help_text-deprecation:
    
  1211. 
    
  1212. Munging of help text of model form fields for ``ManyToManyField`` fields
    
  1213. ------------------------------------------------------------------------
    
  1214. 
    
  1215. All special handling of the ``help_text`` attribute of ``ManyToManyField`` model
    
  1216. fields performed by standard model or model form fields as described in
    
  1217. :ref:`m2m-help_text` above is deprecated and will be removed in Django 1.8.
    
  1218. 
    
  1219. Help text of these fields will need to be handled either by applications, custom
    
  1220. form fields or widgets, just like happens with the rest of the model field
    
  1221. types.