1.6.txt 47 KB

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