1.6.txt 54 KB

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