1.6.txt 46 KB

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