1.6.txt 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  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. Python compatibility
  26. ====================
  27. Django 1.6, like Django 1.5, requires Python 2.6.5 or above. Python 3 is also
  28. officially supported. We **highly recommend** the latest minor release for each
  29. supported Python series (2.6.X, 2.7.X, 3.2.X, and 3.3.X).
  30. Django 1.6 will be the final release series to support Python 2.6; beginning
  31. with Django 1.7, the minimum supported Python version will be 2.7.
  32. What's new in Django 1.6
  33. ========================
  34. Simplified default project and app templates
  35. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. The default templates used by :djadmin:`startproject` and :djadmin:`startapp`
  37. have been simplified and modernized. The :doc:`admin
  38. </ref/contrib/admin/index>` is now enabled by default in new projects; the
  39. :doc:`sites </ref/contrib/sites>` framework no longer is. :ref:`clickjacking
  40. prevention <clickjacking-prevention>` is now on and the database defaults to
  41. SQLite.
  42. If the default templates don't suit your tastes, you can use :ref:`custom
  43. project and app templates <custom-app-and-project-templates>`.
  44. Improved transaction management
  45. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  46. Django's transaction management was overhauled. Database-level autocommit is
  47. now turned on by default. This makes transaction handling more explicit and
  48. should improve performance. The existing APIs were deprecated, and new APIs
  49. were introduced, as described in the :doc:`transaction management docs
  50. </topics/db/transactions>`.
  51. Please review carefully the list of :ref:`known backwards-incompatibilities
  52. <transactions-upgrading-from-1.5>` to determine if you need to make changes in
  53. your code.
  54. Persistent database connections
  55. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. Django now supports reusing the same database connection for several requests.
  57. This avoids the overhead of re-establishing a connection at the beginning of
  58. each request. For backwards compatibility, this feature is disabled by
  59. default. See :ref:`persistent-database-connections` for details.
  60. Discovery of tests in any test module
  61. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. Django 1.6 ships with a new test runner that allows more flexibility in the
  63. location of tests. The previous runner
  64. (``django.test.simple.DjangoTestSuiteRunner``) found tests only in the
  65. ``models.py`` and ``tests.py`` modules of a Python package in
  66. :setting:`INSTALLED_APPS`.
  67. The new runner (``django.test.runner.DiscoverRunner``) uses the test discovery
  68. features built into ``unittest2`` (the version of ``unittest`` in the
  69. Python 2.7+ standard library, and bundled with Django). With test discovery,
  70. tests can be located in any module whose name matches the pattern ``test*.py``.
  71. In addition, the test labels provided to ``./manage.py test`` to nominate
  72. specific tests to run must now be full Python dotted paths (or directory
  73. paths), rather than ``applabel.TestCase.test_method_name`` pseudo-paths. This
  74. allows running tests located anywhere in your codebase, rather than only in
  75. :setting:`INSTALLED_APPS`. For more details, see :doc:`/topics/testing/index`.
  76. This change is backwards-incompatible; see the :ref:`backwards-incompatibility
  77. notes<new-test-runner>`.
  78. Time zone aware aggregation
  79. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. The support for :doc:`time zones </topics/i18n/timezones>` introduced in
  81. Django 1.4 didn't work well with :meth:`QuerySet.dates()
  82. <django.db.models.query.QuerySet.dates>`: aggregation was always performed in
  83. UTC. This limitation was lifted in Django 1.6. Use :meth:`QuerySet.datetimes()
  84. <django.db.models.query.QuerySet.datetimes>` to perform time zone aware
  85. aggregation on a :class:`~django.db.models.DateTimeField`.
  86. Support for savepoints in SQLite
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. Django 1.6 adds support for savepoints in SQLite, with some :ref:`limitations
  89. <savepoints-in-sqlite>`.
  90. ``BinaryField`` model field
  91. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. A new :class:`django.db.models.BinaryField` model field allows storage of raw
  93. binary data in the database.
  94. GeoDjango form widgets
  95. ~~~~~~~~~~~~~~~~~~~~~~
  96. GeoDjango now provides :ref:`form fields and widgets <ref-gis-forms-api>` for
  97. its geo-specialized fields. They are OpenLayers-based by default, but they can
  98. be customized to use any other JS framework.
  99. ``check`` management command added for verifying compatibility
  100. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. A :djadmin:`check` management command was added, enabling you to verify if your
  102. current configuration (currently oriented at settings) is compatible with the
  103. current version of Django.
  104. :meth:`Model.save() <django.db.models.Model.save()>` algorithm changed
  105. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  106. The :meth:`Model.save() <django.db.models.Model.save()>` method now
  107. tries to directly ``UPDATE`` the database if the instance has a primary
  108. key value. Previously ``SELECT`` was performed to determine if ``UPDATE``
  109. or ``INSERT`` were needed. The new algorithm needs only one query for
  110. updating an existing row while the old algorithm needed two. See
  111. :meth:`Model.save() <django.db.models.Model.save()>` for more details.
  112. In some rare cases the database doesn't report that a matching row was
  113. found when doing an ``UPDATE``. An example is the PostgreSQL ``ON UPDATE``
  114. trigger which returns ``NULL``. In such cases it is possible to set
  115. :attr:`django.db.models.Options.select_on_save` flag to force saving to
  116. use the old algorithm.
  117. Minor features
  118. ~~~~~~~~~~~~~~
  119. * Authentication backends can raise ``PermissionDenied`` to immediately fail
  120. the authentication chain.
  121. * The ``HttpOnly`` flag can be set on the CSRF cookie with
  122. :setting:`CSRF_COOKIE_HTTPONLY`.
  123. * The :meth:`~django.test.TransactionTestCase.assertQuerysetEqual` now checks
  124. for undefined order and raises :exc:`~exceptions.ValueError` if undefined
  125. order is spotted. The order is seen as undefined if the given ``QuerySet``
  126. isn't ordered and there are more than one ordered values to compare against.
  127. * Added :meth:`~django.db.models.query.QuerySet.earliest` for symmetry with
  128. :meth:`~django.db.models.query.QuerySet.latest`.
  129. * In addition to :lookup:`year`, :lookup:`month` and :lookup:`day`, the ORM
  130. now supports :lookup:`hour`, :lookup:`minute` and :lookup:`second` lookups.
  131. * Django now wraps all PEP-249 exceptions.
  132. * The default widgets for :class:`~django.forms.EmailField`,
  133. :class:`~django.forms.URLField`, :class:`~django.forms.IntegerField`,
  134. :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` use
  135. the new type attributes available in HTML5 (``type='email'``, ``type='url'``,
  136. ``type='number'``). Note that due to erratic support of the ``number``
  137. input type with localized numbers in current browsers, Django only uses it
  138. when numeric fields are not localized.
  139. * The ``number`` argument for :ref:`lazy plural translations
  140. <lazy-plural-translations>` can be provided at translation time rather than
  141. at definition time.
  142. * For custom management commands: Verification of the presence of valid
  143. settings in commands that ask for it by using the
  144. :attr:`~django.core.management.BaseCommand.can_import_settings` internal
  145. option is now performed independently from handling of the locale that
  146. should be active during the execution of the command. The latter can now be
  147. influenced by the new
  148. :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal
  149. option. See :ref:`management-commands-and-locales` for more details.
  150. * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of
  151. :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with
  152. its ``object``’s ``__dict__``.
  153. * :class:`~django.http.HttpResponseRedirect` and
  154. :class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
  155. attribute (equivalent to the URL the response will redirect to).
  156. * The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
  157. protocol available.
  158. * Added :class:`~django.contrib.messages.views.SuccessMessageMixin` which
  159. provides a ``success_message`` attribute for
  160. :class:`~django.views.generic.edit.FormView` based classes.
  161. * Added the :attr:`django.db.models.ForeignKey.db_constraint` and
  162. :attr:`django.db.models.ManyToManyField.db_constraint` options.
  163. * The jQuery library embedded in the admin has been upgraded to version 1.9.1.
  164. * Syndication feeds (:mod:`django.contrib.syndication`) can now pass extra
  165. context through to feed templates using a new
  166. :meth:`Feed.get_context_data()
  167. <django.contrib.syndication.Feed.get_context_data>` callback.
  168. * The admin list columns have a ``column-<field_name>`` class in the HTML
  169. so the columns header can be styled with CSS, e.g. to set a column width.
  170. * The :ref:`isolation level<database-isolation-level>` can be customized under
  171. PostgreSQL.
  172. * The :ttag:`blocktrans` template tag now respects
  173. :setting:`TEMPLATE_STRING_IF_INVALID` for variables not present in the
  174. context, just like other template constructs.
  175. * ``SimpleLazyObject``\s will now present more helpful representations in shell
  176. debugging situations.
  177. * Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
  178. with the OpenLayers widget in the admin.
  179. * The documentation contains a :doc:`deployment checklist
  180. </howto/deployment/checklist>`.
  181. * The :djadmin:`diffsettings` command gained a ``--all`` option.
  182. * ``django.forms.fields.Field.__init__`` now calls ``super()``, allowing
  183. field mixins to implement ``__init__()`` methods that will reliably be
  184. called.
  185. * The ``validate_max`` parameter was added to ``BaseFormSet`` and
  186. :func:`~django.forms.formsets.formset_factory`, and ``ModelForm`` and inline
  187. versions of the same. The behavior of validation for formsets with
  188. ``max_num`` was clarified. The previously undocumented behavior that
  189. hardened formsets against memory exhaustion attacks was documented,
  190. and the undocumented limit of the higher of 1000 or ``max_num`` forms
  191. was changed so it is always 1000 more than ``max_num``.
  192. * Added ``BCryptSHA256PasswordHasher`` to resolve the password truncation issue
  193. with bcrypt.
  194. * `Pillow`_ is now the preferred image manipulation library to use with Django.
  195. `PIL`_ is pending deprecation (support to be removed in Django 1.8).
  196. To upgrade, you should **first** uninstall PIL, **then** install Pillow.
  197. .. _`Pillow`: https://pypi.python.org/pypi/Pillow
  198. .. _`PIL`: https://pypi.python.org/pypi/PIL
  199. * :class:`~django.forms.ModelForm` accepts several new ``Meta``
  200. options.
  201. * Fields included in the ``localized_fields`` list will be localized
  202. (by setting ``localize`` on the form field).
  203. * The ``labels``, ``help_texts`` and ``error_messages`` options may be used
  204. to customize the default fields, see
  205. :ref:`modelforms-overriding-default-fields` for details.
  206. * The ``choices`` argument to model fields now accepts an iterable of iterables
  207. instead of requiring an iterable of lists or tuples.
  208. * The reason phrase can be customized in HTTP responses using
  209. :attr:`~django.http.HttpResponse.reason_phrase`.
  210. * When giving the URL of the next page for
  211. :func:`~django.contrib.auth.views.logout`,
  212. :func:`~django.contrib.auth.views.password_reset`,
  213. :func:`~django.contrib.auth.views.password_reset_confirm`,
  214. and :func:`~django.contrib.auth.views.password_change`, you can now pass
  215. URL names and they will be resolved.
  216. * The :djadmin:`dumpdata` ``manage.py`` command now has a :djadminopt:`--pks`
  217. option which will allow users to specify the primary keys of objects they
  218. want to dump. This option can only be used with one model.
  219. * Added ``QuerySet`` methods :meth:`~django.db.models.query.QuerySet.first`
  220. and :meth:`~django.db.models.query.QuerySet.last` which are convenience
  221. methods returning the first or last object matching the filters. Returns
  222. ``None`` if there are no objects matching.
  223. * :class:`~django.views.generic.base.View` and
  224. :class:`~django.views.generic.base.RedirectView` now support HTTP ``PATCH``
  225. method.
  226. * :class:`GenericForeignKey <django.contrib.contenttypes.generic.GenericForeignKey>`
  227. now takes an optional
  228. :attr:`~django.contrib.contenttypes.generic.GenericForeignKey.for_concrete_model`
  229. argument, which when set to ``False`` allows the field to reference proxy
  230. models. The default is ``True`` to retain the old behavior.
  231. * The :class:`~django.middleware.locale.LocaleMiddleware` now stores the active
  232. language in session if it is not present there. This prevents loss of
  233. language settings after session flush, e.g. logout.
  234. * :exc:`~django.core.exceptions.SuspiciousOperation` has been differentiated
  235. into a number of subclasses, and each will log to a matching named logger
  236. under the ``django.security`` logging hierarchy. Along with this change,
  237. a ``handler400`` mechanism and default view are used whenever
  238. a ``SuspiciousOperation`` reaches the WSGI handler to return an
  239. ``HttpResponseBadRequest``.
  240. * The :exc:`~django.core.exceptions.DoesNotExist` exception now includes a
  241. message indicating the name of the attribute used for the lookup.
  242. * The :meth:`~django.db.models.query.QuerySet.get_or_create` method no longer
  243. requires at least one keyword argument.
  244. * The :class:`~django.test.SimpleTestCase` class includes a new assertion
  245. helper for testing formset errors:
  246. :meth:`~django.test.SimpleTestCase.assertFormsetError`.
  247. * The list of related fields added to a
  248. :class:`~django.db.models.query.QuerySet` by
  249. :meth:`~django.db.models.query.QuerySet.select_related` can be cleared using
  250. ``select_related(None)``.
  251. * The :meth:`~django.contrib.admin.InlineModelAdmin.get_extra` and
  252. :meth:`~django.contrib.admin.InlineModelAdmin.get_max_num` methods on
  253. :class:`~django.contrib.admin.InlineModelAdmin` may be overridden to
  254. customize the extra and maximum number of inline forms.
  255. * Formsets now have a
  256. :meth:`~django.forms.formsets.BaseFormSet.total_error_count` method.
  257. * :class:`~django.forms.ModelForm` fields can now override error messages
  258. defined in model fields by using the
  259. :attr:`~django.forms.Field.error_messages` argument of a ``Field``’s
  260. constructor. To take advantage of this new feature with your custom fields,
  261. :ref:`see the updated recommendation <raising-validation-error>` for raising
  262. a ``ValidationError``.
  263. * :class:`~django.contrib.admin.ModelAdmin` now preserves filters on the list view
  264. after creating, editing or deleting an object. It's possible to restore the previous
  265. behavior of clearing filters by setting the
  266. :attr:`~django.contrib.admin.ModelAdmin.preserve_filters` attribute to ``False``.
  267. * Added
  268. :meth:`FormMixin.get_prefix<django.views.generic.edit.FormMixin.get_prefix>`
  269. (which returns
  270. :attr:`FormMixin.prefix<django.views.generic.edit.FormMixin.prefix>` by
  271. default) to allow customizing the :attr:`~django.forms.Form.prefix` of the
  272. form.
  273. * Raw queries (``Manager.raw()`` or ``cursor.execute()``) can now use the
  274. "pyformat" parameter style, where placeholders in the query are given as
  275. ``'%(name)s'`` and the parameters are passed as a dictionary rather than
  276. a list (except on SQLite). This has long been possible (but not officially
  277. supported) on MySQL and PostgreSQL, and is now also available on Oracle.
  278. * The default iteration count for the PBKDF2 password hasher has been
  279. increased by 20%. This backwards compatible change will not affect
  280. existing passwords or users who have subclassed
  281. `django.contrib.auth.hashers.PBKDF2PasswordHasher`` to change the
  282. default value.
  283. Backwards incompatible changes in 1.6
  284. =====================================
  285. .. warning::
  286. In addition to the changes outlined in this section, be sure to review the
  287. :doc:`deprecation plan </internals/deprecation>` for any features that
  288. have been removed. If you haven't updated your code within the
  289. deprecation timeline for a given feature, its removal may appear as a
  290. backwards incompatible change.
  291. New transaction management model
  292. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  293. Behavior changes
  294. ^^^^^^^^^^^^^^^^
  295. Database-level autocommit is enabled by default in Django 1.6. While this
  296. doesn't change the general spirit of Django's transaction management, there
  297. are a few known backwards-incompatibilities, described in the :ref:`transaction
  298. management docs <transactions-upgrading-from-1.5>`. You should review your
  299. code to determine if you're affected.
  300. Savepoints and ``assertNumQueries``
  301. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  302. The changes in transaction management may result in additional statements to
  303. create, release or rollback savepoints. This is more likely to happen with
  304. SQLite, since it didn't support savepoints until this release.
  305. If tests using :meth:`~django.test.TransactionTestCase.assertNumQueries` fail
  306. because of a higher number of queries than expected, check that the extra
  307. queries are related to savepoints, and adjust the expected number of queries
  308. accordingly.
  309. Autocommit option for PostgreSQL
  310. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  311. In previous versions, database-level autocommit was only an option for
  312. PostgreSQL, and it was disabled by default. This option is now :ref:`ignored
  313. <postgresql-autocommit-mode>` and can be removed.
  314. .. _new-test-runner:
  315. New test runner
  316. ~~~~~~~~~~~~~~~
  317. In order to maintain greater consistency with Python's unittest module, the new
  318. test runner (``django.test.runner.DiscoverRunner``) does not automatically
  319. support some types of tests that were supported by the previous runner:
  320. * Tests in ``models.py`` and ``tests/__init__.py`` files will no longer be
  321. found and run. Move them to a file whose name begins with ``test``.
  322. * Doctests will no longer be automatically discovered. To integrate doctests in
  323. your test suite, follow the `recommendations in the Python documentation`_.
  324. Django bundles a modified version of the :mod:`doctest` module from the Python
  325. standard library (in ``django.test._doctest``) and includes some additional
  326. doctest utilities. These utilities are deprecated and will be removed in Django
  327. 1.8; doctest suites should be updated to work with the standard library's
  328. doctest module (or converted to unittest-compatible tests).
  329. If you wish to delay updates to your test suite, you can set your
  330. :setting:`TEST_RUNNER` setting to ``django.test.simple.DjangoTestSuiteRunner``
  331. to fully restore the old test behavior. ``DjangoTestSuiteRunner`` is deprecated
  332. but will not be removed from Django until version 1.8.
  333. .. _recommendations in the Python documentation: http://docs.python.org/2/library/doctest.html#unittest-api
  334. Time zone-aware ``day``, ``month``, and ``week_day`` lookups
  335. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  336. Django 1.6 introduces time zone support for :lookup:`day`, :lookup:`month`,
  337. and :lookup:`week_day` lookups when :setting:`USE_TZ` is ``True``. These
  338. lookups were previously performed in UTC regardless of the current time zone.
  339. This requires :ref:`time zone definitions in the database
  340. <database-time-zone-definitions>`. If you're using SQLite, you must install
  341. pytz_. If you're using MySQL, you must install pytz_ and load the time zone
  342. tables with `mysql_tzinfo_to_sql`_.
  343. .. _pytz: http://pytz.sourceforge.net/
  344. .. _mysql_tzinfo_to_sql: http://dev.mysql.com/doc/refman/5.5/en/mysql-tzinfo-to-sql.html
  345. Addition of ``QuerySet.datetimes()``
  346. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  347. When the :doc:`time zone support </topics/i18n/timezones>` added in Django 1.4
  348. was active, :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>`
  349. lookups returned unexpected results, because the aggregation was performed in
  350. UTC. To fix this, Django 1.6 introduces a new API, :meth:`QuerySet.datetimes()
  351. <django.db.models.query.QuerySet.datetimes>`. This requires a few changes in
  352. your code.
  353. ``QuerySet.dates()`` returns ``date`` objects
  354. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  355. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` now returns a
  356. list of :class:`~datetime.date`. It used to return a list of
  357. :class:`~datetime.datetime`.
  358. :meth:`QuerySet.datetimes() <django.db.models.query.QuerySet.datetimes>`
  359. returns a list of :class:`~datetime.datetime`.
  360. ``QuerySet.dates()`` no longer usable on ``DateTimeField``
  361. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  362. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` raises an
  363. error if it's used on :class:`~django.db.models.DateTimeField` when time
  364. zone support is active. Use :meth:`QuerySet.datetimes()
  365. <django.db.models.query.QuerySet.datetimes>` instead.
  366. ``date_hierarchy`` requires time zone definitions
  367. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  368. The :attr:`~django.contrib.admin.ModelAdmin.date_hierarchy` feature of the
  369. admin now relies on :meth:`QuerySet.datetimes()
  370. <django.db.models.query.QuerySet.datetimes>` when it's used on a
  371. :class:`~django.db.models.DateTimeField`.
  372. This requires time zone definitions in the database when :setting:`USE_TZ` is
  373. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  374. ``date_list`` in generic views requires time zone definitions
  375. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  376. For the same reason, accessing ``date_list`` in the context of a date-based
  377. generic view requires time zone definitions in the database when the view is
  378. based on a :class:`~django.db.models.DateTimeField` and :setting:`USE_TZ` is
  379. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  380. New lookups may clash with model fields
  381. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  382. Django 1.6 introduces ``hour``, ``minute``, and ``second`` lookups on
  383. :class:`~django.db.models.DateTimeField`. If you had model fields called
  384. ``hour``, ``minute``, or ``second``, the new lookups will clash with you field
  385. names. Append an explicit :lookup:`exact` lookup if this is an issue.
  386. ``BooleanField`` no longer defaults to ``False``
  387. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  388. When a :class:`~django.db.models.BooleanField` doesn't have an explicit
  389. :attr:`~django.db.models.Field.default`, the implicit default value is
  390. ``None``. In previous version of Django, it was ``False``, but that didn't
  391. represent accurately the lack of a value.
  392. Code that relies on the default value being ``False`` may raise an exception
  393. when saving new model instances to the database, because ``None`` isn't an
  394. acceptable value for a :class:`~django.db.models.BooleanField`. You should
  395. either specify ``default=False`` in the field definition, or ensure the field
  396. is set to ``True`` or ``False`` before saving the object.
  397. Translations and comments in templates
  398. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  399. Extraction of translations after comments
  400. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  401. Extraction of translatable literals from templates with the
  402. :djadmin:`makemessages` command now correctly detects i18n constructs when
  403. they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
  404. .. code-block:: html+django
  405. {# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
  406. Location of translator comments
  407. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  408. :ref:`translator-comments-in-templates` specified using ``{#`` / ``#}`` need to
  409. be at the end of a line. If they are not, the comments are ignored and
  410. :djadmin:`makemessages` will generate a warning. For example:
  411. .. code-block:: html+django
  412. {# Translators: This is ignored #}{% trans "Translate me" %}
  413. {{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
  414. <h1>{% trans "Welcome" %}</h1>
  415. Quoting in :func:`~django.core.urlresolvers.reverse`
  416. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  417. When reversing URLs, Django didn't apply :func:`~django.utils.http.urlquote`
  418. to arguments before interpolating them in URL patterns. This bug is fixed in
  419. Django 1.6. If you worked around this bug by applying URL quoting before
  420. passing arguments to :func:`~django.core.urlresolvers.reverse`, this may
  421. result in double-quoting. If this happens, simply remove the URL quoting from
  422. your code.
  423. Storage of IP addresses in the comments app
  424. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  425. The :doc:`comments </ref/contrib/comments/index>` app now uses a
  426. ``GenericIPAddressField`` for storing commenters' IP addresses, to support
  427. comments submitted from IPv6 addresses. Until now, it stored them in an
  428. ``IPAddressField``, which is only meant to support IPv4. When saving a comment
  429. made from an IPv6 address, the address would be silently truncated on MySQL
  430. databases, and raise an exception on Oracle. You will need to change the
  431. column type in your database to benefit from this change.
  432. For MySQL, execute this query on your project's database:
  433. .. code-block:: sql
  434. ALTER TABLE django_comments MODIFY ip_address VARCHAR(39);
  435. For Oracle, execute this query:
  436. .. code-block:: sql
  437. ALTER TABLE DJANGO_COMMENTS MODIFY (ip_address VARCHAR2(39));
  438. If you do not apply this change, the behavior is unchanged: on MySQL, IPv6
  439. addresses are silently truncated; on Oracle, an exception is generated. No
  440. database change is needed for SQLite or PostgreSQL databases.
  441. Percent literals in ``cursor.execute`` queries
  442. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  443. When you are running raw SQL queries through the
  444. :ref:`cursor.execute <executing-custom-sql>` method, the rule about doubling
  445. percent literals (``%``) inside the query has been unified. Past behavior
  446. depended on the database backend. Now, across all backends, you only need to
  447. double literal percent characters if you are also providing replacement
  448. parameters. For example::
  449. # No parameters, no percent doubling
  450. cursor.execute("SELECT foo FROM bar WHERE baz = '30%'")
  451. # Parameters passed, non-placeholders have to be doubled
  452. cursor.execute("SELECT foo FROM bar WHERE baz = '30%%' and id = %s", [self.id])
  453. ``SQLite`` users need to check and update such queries.
  454. .. _m2m-help_text:
  455. Help text of model form fields for ManyToManyField fields
  456. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  457. HTML rendering of model form fields corresponding to
  458. :class:`~django.db.models.ManyToManyField` ORM model fields used to get the
  459. hard-coded sentence
  460. *Hold down "Control", or "Command" on a Mac, to select more than one.*
  461. (or its translation to the active locale) imposed as the help legend shown along
  462. them if neither :attr:`model <django.db.models.Field.help_text>` nor :attr:`form
  463. <django.forms.Field.help_text>` ``help_text`` attribute was specified by the
  464. user (or appended to, if ``help_text`` was provided.)
  465. This happened always, possibly even with form fields implementing user
  466. interactions that don't involve a keyboard and/or a mouse and was handled at the
  467. model field layer.
  468. Starting with Django 1.6 this doesn't happen anymore.
  469. The change can affect you in a backward incompatible way if you employ custom
  470. model form fields and/or widgets for ``ManyToManyField`` model fields whose UIs
  471. do rely on the automatic provision of the mentioned hard-coded sentence. These
  472. form field implementations need to adapt to the new scenario by providing their
  473. own handling of the ``help_text`` attribute.
  474. Applications that use Django :doc:`model form </topics/forms/modelforms>`
  475. facilities together with Django built-in form :doc:`fields </ref/forms/fields>`
  476. and :doc:`widgets </ref/forms/widgets>` aren't affected but need to be aware of
  477. what's described in :ref:`m2m-help_text-deprecation` below.
  478. This is because, as an ad-hoc temporary backward-compatibility provision, the
  479. described non-standard behavior has been preserved but moved to the model form
  480. field layer and occurs only when the associated widget is
  481. :class:`~django.forms.SelectMultiple` or selected subclasses.
  482. QuerySet iteration
  483. ~~~~~~~~~~~~~~~~~~
  484. The ``QuerySet`` iteration was changed to immediately convert all fetched
  485. rows to ``Model`` objects. In Django 1.5 and earlier the fetched rows were
  486. converted to ``Model`` objects in chunks of 100.
  487. Existing code will work, but the amount of rows converted to objects
  488. might change in certain use cases. Such usages include partially looping
  489. over a queryset or any usage which ends up doing ``__bool__`` or
  490. ``__contains__``.
  491. Notably most database backends did fetch all the rows in one go already in
  492. 1.5.
  493. It is still possible to convert the fetched rows to ``Model`` objects
  494. lazily by using the :meth:`~django.db.models.query.QuerySet.iterator()`
  495. method.
  496. :meth:`BoundField.label_tag<django.forms.BoundField.label_tag>` now includes the form's :attr:`~django.forms.Form.label_suffix`
  497. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  498. This is consistent with how methods like
  499. :meth:`Form.as_p<django.forms.Form.as_p>` and
  500. :meth:`Form.as_ul<django.forms.Form.as_ul>` render labels.
  501. If you manually render ``label_tag`` in your templates:
  502. .. code-block:: html+django
  503. {{ form.my_field.label_tag }}: {{ form.my_field }}
  504. you'll want to remove the colon (or whatever other separator you may be
  505. using) to avoid duplicating it when upgrading to Django 1.6. The following
  506. template in Django 1.6 will render identically to the above template in Django
  507. 1.5, except that the colon will appear inside the ``<label>`` element.
  508. .. code-block:: html+django
  509. {{ form.my_field.label_tag }} {{ form.my_field }}
  510. will render something like:
  511. .. code-block:: html
  512. <label for="id_my_field">My Field:</label> <input id="id_my_field" type="text" name="my_field" />
  513. If you want to keep the current behavior of rendering ``label_tag`` without
  514. the ``label_suffix``, instantiate the form ``label_suffix=''``. You can also
  515. customize the ``label_suffix`` on a per-field basis using the new
  516. ``label_suffix`` parameter on :meth:`~django.forms.BoundField.label_tag`.
  517. Admin views ``_changelist_filters`` GET parameter
  518. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  519. To achieve preserving and restoring list view filters, admin views now
  520. pass around the `_changelist_filters` GET parameter. It's important that you
  521. account for that change if you have custom admin templates or if your tests
  522. rely on the previous URLs. If you want to revert to the original behavior you
  523. can set the
  524. :attr:`~django.contrib.admin.ModelAdmin.preserve_filters` attribute to ``False``.
  525. ``django.contrib.auth`` password reset uses base 64 encoding of ``User`` PK
  526. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  527. Past versions of Django used base 36 encoding of the ``User`` primary key in
  528. the password reset views and URLs
  529. (:func:`django.contrib.auth.views.password_reset_confirm`). Base 36 encoding is
  530. sufficient if the user primary key is an integer, however, with the
  531. introduction of custom user models in Django 1.5, that assumption may no longer
  532. be true.
  533. :func:`django.contrib.auth.views.password_reset_confirm` has been modified to
  534. take a ``uidb64`` parameter instead of ``uidb36``. If you are reversing this
  535. view, for example in a custom ``password_reset_email.html`` template, be sure
  536. to update your code.
  537. A temporary shim for :func:`django.contrib.auth.views.password_reset_confirm`
  538. that will allow password reset links generated prior to Django 1.6 to continue
  539. to work has been added to provide backwards compatibility; this will be removed
  540. in Django 1.7. Thus, as long as your site has been running Django 1.6 for more
  541. than :setting:`PASSWORD_RESET_TIMEOUT_DAYS`, this change will have no effect.
  542. If not (for example, if you upgrade directly from Django 1.5 to Django 1.7),
  543. then any password reset links generated before you upgrade to Django 1.7 or
  544. later won't work after the upgrade.
  545. In addition, if you have any custom password reset URLs, you will need to
  546. update them by replacing ``uidb36`` with ``uidb64`` and the dash that follows
  547. that pattern with a slash. Also add ``_\-`` to the list of characters that may
  548. match the ``uidb64`` pattern.
  549. For example::
  550. url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
  551. 'django.contrib.auth.views.password_reset_confirm',
  552. name='password_reset_confirm'),
  553. becomes::
  554. url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
  555. 'django.contrib.auth.views.password_reset_confirm',
  556. name='password_reset_confirm'),
  557. You may also want to add the shim to support the old style reset links. Using
  558. the example above, you would modify the existing url by replacing
  559. ``django.contrib.auth.views.password_reset_confirm`` with
  560. ``django.contrib.auth.views.password_reset_confirm_uidb36`` and also remove
  561. the ``name`` argument so it doesn't conflict with the new url::
  562. url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
  563. 'django.contrib.auth.views.password_reset_confirm_uidb36'),
  564. You can remove this url pattern after your app has been deployed with Django
  565. 1.6 for :setting:`PASSWORD_RESET_TIMEOUT_DAYS`.
  566. Default session serialization switched to JSON
  567. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  568. Historically, :mod:`django.contrib.sessions` used :mod:`pickle` to serialize
  569. session data before storing it in the backend. If you're using the :ref:`signed
  570. cookie session backend<cookie-session-backend>` and :setting:`SECRET_KEY` is
  571. known by an attacker (there isn't an inherent vulnerability in Django that
  572. would cause it to leak), the attacker could insert a string into his session
  573. which, when unpickled, executes arbitrary code on the server. The technique for
  574. doing so is simple and easily available on the internet. Although the cookie
  575. session storage signs the cookie-stored data to prevent tampering, a
  576. :setting:`SECRET_KEY` leak immediately escalates to a remote code execution
  577. vulnerability.
  578. This attack can be mitigated by serializing session data using JSON rather
  579. than :mod:`pickle`. To facilitate this, Django 1.5.3 introduced a new setting,
  580. :setting:`SESSION_SERIALIZER`, to customize the session serialization format.
  581. For backwards compatibility, this setting defaulted to using :mod:`pickle`
  582. in Django 1.5.3, but we've changed the default to JSON in 1.6. If you upgrade
  583. and switch from pickle to JSON, sessions created before the upgrade will be
  584. lost. While JSON serialization does not support all Python objects like
  585. :mod:`pickle` does, we highly recommend using JSON-serialized sessions. Also,
  586. as JSON requires string keys, you will likely run into problems if you are
  587. using non-string keys in ``request.session``. See the
  588. :ref:`session_serialization` documentation for more details.
  589. 4096-byte limit on passwords
  590. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  591. .. note::
  592. This behavior was also added in the Django 1.5.4 and 1.4.8 security
  593. releases.
  594. Historically, Django has imposed no length limit on plaintext
  595. passwords. This enables a denial-of-service attack through submission
  596. of bogus but extremely large passwords, tying up server resources
  597. performing the (expensive, and increasingly expensive with the length
  598. of the password) calculation of the corresponding hash.
  599. Django now imposes a 4096-byte limit on password length, and will fail
  600. authentication with any submitted password of greater length.
  601. Miscellaneous
  602. ~~~~~~~~~~~~~
  603. * The ``django.db.models.query.EmptyQuerySet`` can't be instantiated any more -
  604. it is only usable as a marker class for checking if
  605. :meth:`~django.db.models.query.QuerySet.none` has been called:
  606. ``isinstance(qs.none(), EmptyQuerySet)``
  607. * If your CSS/Javascript code used to access HTML input widgets by type, you
  608. should review it as ``type='text'`` widgets might be now output as
  609. ``type='email'``, ``type='url'`` or ``type='number'`` depending on their
  610. corresponding field type.
  611. * Form field's :attr:`~django.forms.Field.error_messages` that contain a
  612. placeholder should now always use a named placeholder (``"Value '%(value)s' is
  613. too big"`` instead of ``"Value '%s' is too big"``). See the corresponding
  614. field documentation for details about the names of the placeholders. The
  615. changes in 1.6 particularly affect :class:`~django.forms.DecimalField` and
  616. :class:`~django.forms.ModelMultipleChoiceField`.
  617. * There have been changes in the way timeouts are handled in cache backends.
  618. Explicitly passing in ``timeout=None`` no longer results in using the
  619. default timeout. It will now set a non-expiring timeout. Passing 0 into the
  620. memcache backend no longer uses the default timeout, and now will
  621. set-and-expire-immediately the value.
  622. * The ``django.contrib.flatpages`` app used to set custom HTTP headers for
  623. debugging purposes. This functionality was not documented and made caching
  624. ineffective so it has been removed, along with its generic implementation,
  625. previously available in ``django.core.xheaders``.
  626. * The ``XViewMiddleware`` has been moved from ``django.middleware.doc`` to
  627. ``django.contrib.admindocs.middleware`` because it is an implementation
  628. detail of admindocs, proven not to be reusable in general.
  629. * :class:`~django.db.models.GenericIPAddressField` will now only allow
  630. ``blank`` values if ``null`` values are also allowed. Creating a
  631. ``GenericIPAddressField`` where ``blank`` is allowed but ``null`` is not
  632. will trigger a model validation error because ``blank`` values are always
  633. stored as ``null``. Previously, storing a ``blank`` value in a field which
  634. did not allow ``null`` would cause a database exception at runtime.
  635. * If a :class:`~django.core.urlresolvers.NoReverseMatch` exception is raised
  636. from a method when rendering a template, it is not silenced. For example,
  637. ``{{ obj.view_href }}`` will cause template rendering to fail if
  638. ``view_href()`` raises ``NoReverseMatch``. There is no change to the
  639. ``{% url %}`` tag, it causes template rendering to fail like always when
  640. ``NoReverseMatch`` is raised.
  641. * :meth:`django.test.Client.logout` now calls
  642. :meth:`django.contrib.auth.logout` which will send the
  643. :func:`~django.contrib.auth.signals.user_logged_out` signal.
  644. * :ref:`Authentication views <built-in-auth-views>` are now reversed by name,
  645. not their locations in ``django.contrib.auth.views``. If you are using the
  646. views without a ``name``, you should update your ``urlpatterns`` to use
  647. :meth:`~django.conf.urls.url` with the ``name`` parameter. For example::
  648. (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete')
  649. becomes::
  650. url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete')
  651. * :class:`~django.views.generic.base.RedirectView` now has a `pattern_name`
  652. attribute which allows it to choose the target by reversing the URL.
  653. * In Django 1.4 and 1.5, a blank string was unintentionally not considered to
  654. be a valid password. This meant
  655. :meth:`~django.contrib.auth.models.User.set_password()` would save a blank
  656. password as an unusable password like
  657. :meth:`~django.contrib.auth.models.User.set_unusable_password()` does, and
  658. thus :meth:`~django.contrib.auth.models.User.check_password()` always
  659. returned ``False`` for blank passwords. This has been corrected in this
  660. release: blank passwords are now valid.
  661. * The admin :attr:`~django.contrib.admin.ModelAdmin.changelist_view` previously
  662. accepted a ``pop`` GET parameter to signify it was to be displayed in a popup.
  663. This parameter has been renamed to ``_popup`` to be consistent with the rest
  664. of the admin views. You should update your custom templates if they use the
  665. previous parameter name.
  666. * :meth:`~django.core.validators.validate_email` now accepts email addresses
  667. with ``localhost`` as the domain.
  668. * The :djadminopt:`--keep-pot` option was added to :djadmin:`makemessages`
  669. to prevent django from deleting the temporary .pot file it generates before
  670. creating the .po file.
  671. Features deprecated in 1.6
  672. ==========================
  673. Transaction management APIs
  674. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  675. Transaction management was completely overhauled in Django 1.6, and the
  676. current APIs are deprecated:
  677. - ``django.middleware.transaction.TransactionMiddleware``
  678. - ``django.db.transaction.autocommit``
  679. - ``django.db.transaction.commit_on_success``
  680. - ``django.db.transaction.commit_manually``
  681. - the ``TRANSACTIONS_MANAGED`` setting
  682. The reasons for this change and the upgrade path are described in the
  683. :ref:`transactions documentation <transactions-upgrading-from-1.5>`.
  684. ``django.contrib.comments``
  685. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  686. Django's comment framework has been deprecated and is no longer supported. It
  687. will be available in Django 1.6 and 1.7, and removed in Django 1.8. Most users
  688. will be better served with a custom solution, or a hosted product like Disqus__.
  689. The code formerly known as ``django.contrib.comments`` is `still available
  690. in an external repository`__.
  691. __ https://disqus.com/
  692. __ https://github.com/django/django-contrib-comments
  693. Support for PostgreSQL versions older than 8.4
  694. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  695. The end of upstream support periods was reached in December 2011 for
  696. PostgreSQL 8.2 and in February 2013 for 8.3. As a consequence, Django 1.6 sets
  697. 8.4 as the minimum PostgreSQL version it officially supports.
  698. You're strongly encouraged to use the most recent version of PostgreSQL
  699. available, because of performance improvements and to take advantage of the
  700. native streaming replication available in PostgreSQL 9.x.
  701. Changes to :ttag:`cycle` and :ttag:`firstof`
  702. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  703. The template system generally escapes all variables to avoid XSS attacks.
  704. However, due to an accident of history, the :ttag:`cycle` and :ttag:`firstof`
  705. tags render their arguments as-is.
  706. Django 1.6 starts a process to correct this inconsistency. The ``future``
  707. template library provides alternate implementations of :ttag:`cycle` and
  708. :ttag:`firstof` that autoescape their inputs. If you're using these tags,
  709. you're encourage to include the following line at the top of your templates to
  710. enable the new behavior::
  711. {% load cycle from future %}
  712. or::
  713. {% load firstof from future %}
  714. The tags implementing the old behavior have been deprecated, and in Django
  715. 1.8, the old behavior will be replaced with the new behavior. To ensure
  716. compatibility with future versions of Django, existing templates should be
  717. modified to use the ``future`` versions.
  718. If necessary, you can temporarily disable auto-escaping with
  719. :func:`~django.utils.safestring.mark_safe` or :ttag:`{% autoescape off %}
  720. <autoescape>`.
  721. ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting
  722. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  723. ``CacheMiddleware`` used to provide a way to cache requests only if they
  724. weren't made by a logged-in user. This mechanism was largely ineffective
  725. because the middleware correctly takes into account the ``Vary: Cookie`` HTTP
  726. header, and this header is being set on a variety of occasions, such as:
  727. * accessing the session, or
  728. * using CSRF protection, which is turned on by default, or
  729. * using a client-side library which sets cookies, like `Google Analytics`__.
  730. This makes the cache effectively work on a per-session basis regardless of the
  731. ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting.
  732. __ http://www.google.com/analytics/
  733. ``SEND_BROKEN_LINK_EMAILS`` setting
  734. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  735. :class:`~django.middleware.common.CommonMiddleware` used to provide basic
  736. reporting of broken links by email when ``SEND_BROKEN_LINK_EMAILS`` is set to
  737. ``True``.
  738. Because of intractable ordering problems between
  739. :class:`~django.middleware.common.CommonMiddleware` and
  740. :class:`~django.middleware.locale.LocaleMiddleware`, this feature was split
  741. out into a new middleware:
  742. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware`.
  743. If you're relying on this feature, you should add
  744. ``'django.middleware.common.BrokenLinkEmailsMiddleware'`` to your
  745. :setting:`MIDDLEWARE_CLASSES` setting and remove ``SEND_BROKEN_LINK_EMAILS``
  746. from your settings.
  747. ``_has_changed`` method on widgets
  748. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  749. If you defined your own form widgets and defined the ``_has_changed`` method
  750. on a widget, you should now define this method on the form field itself.
  751. ``module_name`` model _meta attribute
  752. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  753. ``Model._meta.module_name`` was renamed to ``model_name``. Despite being a
  754. private API, it will go through a regular deprecation path.
  755. ``get_(add|change|delete)_permission`` model _meta methods
  756. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  757. ``Model._meta.get_(add|change|delete)_permission`` methods were deprecated.
  758. Even if they were not part of the public API they'll also go through
  759. a regular deprecation path.
  760. ``get_query_set`` and similar methods renamed to ``get_queryset``
  761. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  762. Methods that return a ``QuerySet`` such as ``Manager.get_query_set`` or
  763. ``ModelAdmin.queryset`` have been renamed to ``get_queryset``.
  764. ``shortcut`` view and URLconf
  765. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  766. The ``shortcut`` view was moved from ``django.views.defaults`` to
  767. ``django.contrib.contenttypes.views`` shortly after the 1.0 release, but the
  768. old location was never deprecated. This oversight was corrected in Django 1.6
  769. and you should now use the new location.
  770. The URLconf ``django.conf.urls.shortcut`` was also deprecated. If you're
  771. including it in an URLconf, simply replace::
  772. (r'^prefix/', include('django.conf.urls.shortcut')),
  773. with::
  774. (r'^prefix/(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'django.contrib.contenttypes.views.shortcut'),
  775. ``ModelForm`` without ``fields`` or ``exclude``
  776. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  777. Previously, if you wanted a :class:`~django.forms.ModelForm` to use all fields on
  778. the model, you could simply omit the ``Meta.fields`` attribute, and all fields
  779. would be used.
  780. This can lead to security problems where fields are added to the model and,
  781. unintentionally, automatically become editable by end users. In some cases,
  782. particular with boolean fields, it is possible for this problem to be completely
  783. invisible. This is a form of `Mass assignment vulnerability
  784. <http://en.wikipedia.org/wiki/Mass_assignment_vulnerability>`_.
  785. For this reason, this behavior is deprecated, and using the ``Meta.exclude``
  786. option is strongly discouraged. Instead, all fields that are intended for
  787. inclusion in the form should be listed explicitly in the ``fields`` attribute.
  788. If this security concern really does not apply in your case, there is a shortcut
  789. to explicitly indicate that all fields should be used - use the special value
  790. ``"__all__"`` for the fields attribute::
  791. class MyModelForm(ModelForm):
  792. class Meta:
  793. fields = "__all__"
  794. model = MyModel
  795. If you have custom ``ModelForms`` that only need to be used in the admin, there
  796. is another option. The admin has its own methods for defining fields
  797. (``fieldsets`` etc.), and so adding a list of fields to the ``ModelForm`` is
  798. redundant. Instead, simply omit the ``Meta`` inner class of the ``ModelForm``,
  799. or omit the ``Meta.model`` attribute. Since the ``ModelAdmin`` subclass knows
  800. which model it is for, it can add the necessary attributes to derive a
  801. functioning ``ModelForm``. This behavior also works for earlier Django
  802. versions.
  803. ``UpdateView`` and ``CreateView`` without explicit fields
  804. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  805. The generic views :class:`~django.views.generic.edit.CreateView` and
  806. :class:`~django.views.generic.edit.UpdateView`, and anything else derived from
  807. :class:`~django.views.generic.edit.ModelFormMixin`, are vulnerable to the
  808. security problem described in the section above, because they can automatically
  809. create a ``ModelForm`` that uses all fields for a model.
  810. For this reason, if you use these views for editing models, you must also supply
  811. the ``fields`` attribute (new in Django 1.6), which is a list of model fields
  812. and works in the same way as the :class:`~django.forms.ModelForm`
  813. ``Meta.fields`` attribute. Alternatively, you can set set the ``form_class``
  814. attribute to a ``ModelForm`` that explicitly defines the fields to be used.
  815. Defining an ``UpdateView`` or ``CreateView`` subclass to be used with a model
  816. but without an explicit list of fields is deprecated.
  817. .. _m2m-help_text-deprecation:
  818. Munging of help text of model form fields for ``ManyToManyField`` fields
  819. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  820. All special handling of the ``help_text`` attribute of ``ManyToManyField`` model
  821. fields performed by standard model or model form fields as described in
  822. :ref:`m2m-help_text` above is deprecated and will be removed in Django 1.8.
  823. Help text of these fields will need to be handled either by applications, custom
  824. form fields or widgets, just like happens with the rest of the model field
  825. types.