1.6.txt 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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. What's new in Django 1.6
  26. ========================
  27. Simplified default project and app templates
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. The default templates used by :djadmin:`startproject` and :djadmin:`startapp`
  30. have been simplified and modernized. The :doc:`admin
  31. </ref/contrib/admin/index>` is now enabled by default in new projects; the
  32. :doc:`sites </ref/contrib/sites>` framework no longer is. :ref:`Language
  33. detection <how-django-discovers-language-preference>` and :ref:`clickjacking
  34. prevention <clickjacking-prevention>` are turned on.
  35. If the default templates don't suit your tastes, you can use :ref:`custom
  36. project and app templates <custom-app-and-project-templates>`.
  37. Improved transaction management
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. Django's transaction management was overhauled. Database-level autocommit is
  40. now turned on by default. This makes transaction handling more explicit and
  41. should improve performance. The existing APIs were deprecated, and new APIs
  42. were introduced, as described in the :doc:`transaction management docs
  43. </topics/db/transactions>`.
  44. Please review carefully the list of :ref:`known backwards-incompatibilities
  45. <transactions-upgrading-from-1.5>` to determine if you need to make changes in
  46. your code.
  47. Persistent database connections
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. Django now supports reusing the same database connection for several requests.
  50. This avoids the overhead of re-establishing a connection at the beginning of
  51. each request. For backwards compatibility, this feature is disabled by
  52. default. See :ref:`persistent-database-connections` for details.
  53. Time zone aware aggregation
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. The support for :doc:`time zones </topics/i18n/timezones>` introduced in
  56. Django 1.4 didn't work well with :meth:`QuerySet.dates()
  57. <django.db.models.query.QuerySet.dates>`: aggregation was always performed in
  58. UTC. This limitation was lifted in Django 1.6. Use :meth:`QuerySet.datetimes()
  59. <django.db.models.query.QuerySet.datetimes>` to perform time zone aware
  60. aggregation on a :class:`~django.db.models.DateTimeField`.
  61. Support for savepoints in SQLite
  62. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. Django 1.6 adds support for savepoints in SQLite, with some :ref:`limitations
  64. <savepoints-in-sqlite>`.
  65. ``BinaryField`` model field
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. A new :class:`django.db.models.BinaryField` model field allows to store raw
  68. binary data in the database.
  69. Minor features
  70. ~~~~~~~~~~~~~~
  71. * Authentication backends can raise ``PermissionDenied`` to immediately fail
  72. the authentication chain.
  73. * The HttpOnly flag can be set on the CSRF cookie with
  74. :setting:`CSRF_COOKIE_HTTPONLY`.
  75. * The ``assertQuerysetEqual()`` now checks for undefined order and raises
  76. ``ValueError`` if undefined order is spotted. The order is seen as
  77. undefined if the given ``QuerySet`` isn't ordered and there are more than
  78. one ordered values to compare against.
  79. * Added :meth:`~django.db.models.query.QuerySet.earliest` for symmetry with
  80. :meth:`~django.db.models.query.QuerySet.latest`.
  81. * In addition to :lookup:`year`, :lookup:`month` and :lookup:`day`, the ORM
  82. now supports :lookup:`hour`, :lookup:`minute` and :lookup:`second` lookups.
  83. * Django now wraps all PEP-249 exceptions.
  84. * The default widgets for :class:`~django.forms.EmailField`,
  85. :class:`~django.forms.URLField`, :class:`~django.forms.IntegerField`,
  86. :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` use
  87. the new type attributes available in HTML5 (type='email', type='url',
  88. type='number'). Note that due to erratic support of the ``number`` input type
  89. with localized numbers in current browsers, Django only uses it when numeric
  90. fields are not localized.
  91. * The ``number`` argument for :ref:`lazy plural translations
  92. <lazy-plural-translations>` can be provided at translation time rather than
  93. at definition time.
  94. * For custom management commands: Verification of the presence of valid
  95. settings in commands that ask for it by using the
  96. :attr:`~django.core.management.BaseCommand.can_import_settings` internal
  97. option is now performed independently from handling of the locale that
  98. should be active during the execution of the command. The latter can now be
  99. influenced by the new
  100. :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal
  101. option. See :ref:`management-commands-and-locales` for more details.
  102. * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of
  103. :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with
  104. its ``object``\'s ``__dict__``.
  105. * :class:`~django.http.HttpResponseRedirect` and
  106. :class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
  107. attribute (equivalent to the URL the response will redirect to).
  108. * The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
  109. protocol available.
  110. * Added :class:`~django.contrib.messages.views.SuccessMessageMixin` which
  111. provides a ``success_message`` attribute for
  112. :class:`~django.views.generic.edit.FormView` based classes.
  113. * Added the :attr:`django.db.models.ForeignKey.db_constraint` and
  114. :attr:`django.db.models.ManyToManyField.db_constraint` options.
  115. * The jQuery library embedded in the admin has been upgraded to version 1.9.1.
  116. * Syndication feeds (:mod:`django.contrib.syndication`) can now pass extra
  117. context through to feed templates using a new `Feed.get_context_data()`
  118. callback.
  119. * The admin list columns have a ``column-<field_name>`` class in the HTML
  120. so the columns header can be styled with CSS, e.g. to set a column width.
  121. * The isolation level can be customized under PostgreSQL.
  122. * The :ttag:`blocktrans` template tag now respects
  123. :setting:`TEMPLATE_STRING_IF_INVALID` for variables not present in the
  124. context, just like other template constructs.
  125. * SimpleLazyObjects will now present more helpful representations in shell
  126. debugging situations.
  127. * Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
  128. with the OpenLayers widget in the admin.
  129. * The :meth:`Model.save() <django.db.models.Model.save()>` will do
  130. ``UPDATE`` - if not updated - ``INSERT`` instead of ``SELECT`` - if not
  131. found ``INSERT`` else ``UPDATE`` in case the model's primary key is set.
  132. * The documentation contains a :doc:`deployment checklist
  133. </howto/deployment/checklist>`.
  134. * The :djadmin:`diffsettings` comand gained a ``--all`` option.
  135. * ``django.forms.fields.Field.__init__`` now calls ``super()``, allowing
  136. field mixins to implement ``__init__()`` methods that will reliably be
  137. called.
  138. * The ``validate_max`` parameter was added to ``BaseFormSet`` and
  139. :func:`~django.forms.formsets.formset_factory`, and ``ModelForm`` and inline
  140. versions of the same. The behavior of validation for formsets with
  141. ``max_num`` was clarified. The previously undocumented behavior that
  142. hardened formsets against memory exhaustion attacks was documented,
  143. and the undocumented limit of the higher of 1000 or ``max_num`` forms
  144. was changed so it is always 1000 more than ``max_num``.
  145. * Added ``BCryptSHA256PasswordHasher`` to resolve the password truncation issue
  146. with bcrypt.
  147. Backwards incompatible changes in 1.6
  148. =====================================
  149. .. warning::
  150. In addition to the changes outlined in this section, be sure to review the
  151. :doc:`deprecation plan </internals/deprecation>` for any features that
  152. have been removed. If you haven't updated your code within the
  153. deprecation timeline for a given feature, its removal may appear as a
  154. backwards incompatible change.
  155. New transaction management model
  156. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157. Behavior changes
  158. ^^^^^^^^^^^^^^^^
  159. Database-level autocommit is enabled by default in Django 1.6. While this
  160. doesn't change the general spirit of Django's transaction management, there
  161. are a few known backwards-incompatibities, described in the :ref:`transaction
  162. management docs <transactions-upgrading-from-1.5>`. You should review your
  163. code to determine if you're affected.
  164. Savepoints and ``assertNumQueries``
  165. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  166. The changes in transaction management may result in additional statements to
  167. create, release or rollback savepoints. This is more likely to happen with
  168. SQLite, since it didn't support savepoints until this release.
  169. If tests using :meth:`~django.test.TestCase.assertNumQueries` fail because of
  170. a higher number of queries than expected, check that the extra queries are
  171. related to savepoints, and adjust the expected number of queries accordingly.
  172. Autocommit option for PostgreSQL
  173. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  174. In previous versions, database-level autocommit was only an option for
  175. PostgreSQL, and it was disabled by default. This option is now :ref:`ignored
  176. <postgresql-autocommit-mode>` and can be removed.
  177. Addition of ``QuerySet.datetimes()``
  178. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179. When the :doc:`time zone support </topics/i18n/timezones>` added in Django 1.4
  180. was active, :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>`
  181. lookups returned unexpected results, because the aggregation was performed in
  182. UTC. To fix this, Django 1.6 introduces a new API, :meth:`QuerySet.datetimes()
  183. <django.db.models.query.QuerySet.datetimes>`. This requires a few changes in
  184. your code.
  185. ``QuerySet.dates()`` returns ``date`` objects
  186. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  187. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` now returns a
  188. list of :class:`~datetime.date`. It used to return a list of
  189. :class:`~datetime.datetime`.
  190. :meth:`QuerySet.datetimes() <django.db.models.query.QuerySet.datetimes>`
  191. returns a list of :class:`~datetime.datetime`.
  192. ``QuerySet.dates()`` no longer usable on ``DateTimeField``
  193. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  194. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` raises an
  195. error if it's used on :class:`~django.db.models.DateTimeField` when time
  196. zone support is active. Use :meth:`QuerySet.datetimes()
  197. <django.db.models.query.QuerySet.datetimes>` instead.
  198. ``date_hierarchy`` requires time zone definitions
  199. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  200. The :attr:`~django.contrib.admin.ModelAdmin.date_hierarchy` feature of the
  201. admin now relies on :meth:`QuerySet.datetimes()
  202. <django.db.models.query.QuerySet.datetimes>` when it's used on a
  203. :class:`~django.db.models.DateTimeField`.
  204. This requires time zone definitions in the database when :setting:`USE_TZ` is
  205. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  206. ``date_list`` in generic views requires time zone definitions
  207. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  208. For the same reason, accessing ``date_list`` in the context of a date-based
  209. generic view requires time zone definitions in the database when the view is
  210. based on a :class:`~django.db.models.DateTimeField` and :setting:`USE_TZ` is
  211. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  212. New lookups may clash with model fields
  213. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  214. Django 1.6 introduces ``hour``, ``minute``, and ``second`` lookups on
  215. :class:`~django.db.models.DateTimeField`. If you had model fields called
  216. ``hour``, ``minute``, or ``second``, the new lookups will clash with you field
  217. names. Append an explicit :lookup:`exact` lookup if this is an issue.
  218. ``BooleanField`` no longer defaults to ``False``
  219. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220. When a :class:`~django.db.models.BooleanField` doesn't have an explicit
  221. :attr:`~django.db.models.Field.default`, the implicit default value is
  222. ``None``. In previous version of Django, it was ``False``, but that didn't
  223. represent accurately the lack of a value.
  224. Code that relies on the default value being ``False`` may raise an exception
  225. when saving new model instances to the database, because ``None`` isn't an
  226. acceptable value for a :class:`~django.db.models.BooleanField`. You should
  227. either specify ``default=False`` in the field definition, or ensure the field
  228. is set to ``True`` or ``False`` before saving the object.
  229. Translations and comments in templates
  230. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. Extraction of translations after comments
  232. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  233. Extraction of translatable literals from templates with the
  234. :djadmin:`makemessages` command now correctly detects i18n constructs when
  235. they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
  236. .. code-block:: html+django
  237. {# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
  238. Location of translator comments
  239. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  240. Validation of the placement of :ref:`translator-comments-in-templates`
  241. specified using ``{#`` / ``#}`` is now stricter. All translator comments not
  242. located at the end of their respective lines in a template are ignored and a
  243. warning is generated by :djadmin:`makemessages` when it finds them. E.g.:
  244. .. code-block:: html+django
  245. {# Translators: This is ignored #}{% trans "Translate me" %}
  246. {{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
  247. <h1>{% trans "Welcome" %}</h1>
  248. Quoting in :func:`~django.core.urlresolvers.reverse`
  249. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  250. When reversing URLs, Django didn't apply :func:`~django.utils.http.urlquote`
  251. to arguments before interpolating them in URL patterns. This bug is fixed in
  252. Django 1.6. If you worked around this bug by applying URL quoting before
  253. passing arguments to :func:`~django.core.urlresolvers.reverse`, this may
  254. result in double-quoting. If this happens, simply remove the URL quoting from
  255. your code.
  256. Storage of IP addresses in the comments app
  257. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  258. The :doc:`comments </ref/contrib/comments/index>` app now uses a
  259. ``GenericIPAddressField`` for storing commenters' IP addresses, to support
  260. comments submitted from IPv6 addresses. Until now, it stored them in an
  261. ``IPAddressField``, which is only meant to support IPv4. When saving a comment
  262. made from an IPv6 address, the address would be silently truncated on MySQL
  263. databases, and raise an exception on Oracle. You will need to change the
  264. column type in your database to benefit from this change.
  265. For MySQL, execute this query on your project's database:
  266. .. code-block:: sql
  267. ALTER TABLE django_comments MODIFY ip_address VARCHAR(39);
  268. For Oracle, execute this query:
  269. .. code-block:: sql
  270. ALTER TABLE DJANGO_COMMENTS MODIFY (ip_address VARCHAR2(39));
  271. If you do not apply this change, the behaviour is unchanged: on MySQL, IPv6
  272. addresses are silently truncated; on Oracle, an exception is generated. No
  273. database change is needed for SQLite or PostgreSQL databases.
  274. Percent literals in ``cursor.execute`` queries
  275. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  276. When you are running raw SQL queries through the
  277. :ref:`cursor.execute <executing-custom-sql>` method, the rule about doubling
  278. percent literals (``%``) inside the query has been unified. Past behavior
  279. depended on the database backend. Now, across all backends, you only need to
  280. double literal percent characters if you are also providing replacement
  281. parameters. For example::
  282. # No parameters, no percent doubling
  283. cursor.execute("SELECT foo FROM bar WHERE baz = '30%'")
  284. # Parameters passed, non-placeholders have to be doubled
  285. cursor.execute("SELECT foo FROM bar WHERE baz = '30%%' and id = %s", [self.id])
  286. ``SQLite`` users need to check and update such queries.
  287. Miscellaneous
  288. ~~~~~~~~~~~~~
  289. * The ``django.db.models.query.EmptyQuerySet`` can't be instantiated any more -
  290. it is only usable as a marker class for checking if
  291. :meth:`~django.db.models.query.QuerySet.none` has been called:
  292. ``isinstance(qs.none(), EmptyQuerySet)``
  293. * If your CSS/Javascript code used to access HTML input widgets by type, you
  294. should review it as ``type='text'`` widgets might be now output as
  295. ``type='email'``, ``type='url'`` or ``type='number'`` depending on their
  296. corresponding field type.
  297. * Form field's :attr:`~django.forms.Field.error_messages` that contain a
  298. placeholder should now always use a named placeholder (``"Value '%(value)s' is
  299. too big"`` instead of ``"Value '%s' is too big"``). See the corresponding
  300. field documentation for details about the names of the placeholders. The
  301. changes in 1.6 particularly affect :class:`~django.forms.DecimalField` and
  302. :class:`~django.forms.ModelMultipleChoiceField`.
  303. Features deprecated in 1.6
  304. ==========================
  305. Transaction management APIs
  306. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  307. Transaction management was completely overhauled in Django 1.6, and the
  308. current APIs are deprecated:
  309. - ``django.middleware.transaction.TransactionMiddleware``
  310. - ``django.db.transaction.autocommit``
  311. - ``django.db.transaction.commit_on_success``
  312. - ``django.db.transaction.commit_manually``
  313. - the ``TRANSACTIONS_MANAGED`` setting
  314. The reasons for this change and the upgrade path are described in the
  315. :ref:`transactions documentation <transactions-upgrading-from-1.5>`.
  316. ``django.contrib.comments``
  317. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  318. Django's comment framework has been deprecated and is no longer supported. It
  319. will be available in Django 1.6 and 1.7, and removed in Django 1.8. Most users
  320. will be better served with a custom solution, or a hosted product like Disqus__.
  321. The code formerly known as ``django.contrib.comments`` is `still available
  322. in an external repository`__.
  323. __ https://disqus.com/
  324. __ https://github.com/django/django-contrib-comments
  325. Support for PostgreSQL versions older than 8.4
  326. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  327. The end of upstream support periods was reached in December 2011 for
  328. PostgreSQL 8.2 and in February 2013 for 8.3. As a consequence, Django 1.6 sets
  329. 8.4 as the minimum PostgreSQL version it officially supports.
  330. You're strongly encouraged to use the most recent version of PostgreSQL
  331. available, because of performance improvements and to take advantage of the
  332. native streaming replication available in PostgreSQL 9.x.
  333. Changes to :ttag:`cycle` and :ttag:`firstof`
  334. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  335. The template system generally escapes all variables to avoid XSS attacks.
  336. However, due to an accident of history, the :ttag:`cycle` and :ttag:`firstof`
  337. tags render their arguments as-is.
  338. Django 1.6 starts a process to correct this inconsistency. The ``future``
  339. template library provides alternate implementations of :ttag:`cycle` and
  340. :ttag:`firstof` that autoescape their inputs. If you're using these tags,
  341. you're encourage to include the following line at the top of your templates to
  342. enable the new behavior::
  343. {% load cycle from future %}
  344. or::
  345. {% load firstof from future %}
  346. The tags implementing the old behavior have been deprecated, and in Django
  347. 1.8, the old behavior will be replaced with the new behavior. To ensure
  348. compatibility with future versions of Django, existing templates should be
  349. modified to use the ``future`` versions.
  350. If necessary, you can temporarily disable auto-escaping with
  351. :func:`~django.utils.safestring.mark_safe` or :ttag:`{% autoescape off %}
  352. <autoescape>`.
  353. ``SEND_BROKEN_LINK_EMAILS`` setting
  354. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  355. :class:`~django.middleware.common.CommonMiddleware` used to provide basic
  356. reporting of broken links by email when ``SEND_BROKEN_LINK_EMAILS`` is set to
  357. ``True``.
  358. Because of intractable ordering problems between
  359. :class:`~django.middleware.common.CommonMiddleware` and
  360. :class:`~django.middleware.locale.LocaleMiddleware`, this feature was split
  361. out into a new middleware:
  362. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware`.
  363. If you're relying on this feature, you should add
  364. ``'django.middleware.common.BrokenLinkEmailsMiddleware'`` to your
  365. :setting:`MIDDLEWARE_CLASSES` setting and remove ``SEND_BROKEN_LINK_EMAILS``
  366. from your settings.
  367. ``_has_changed`` method on widgets
  368. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  369. If you defined your own form widgets and defined the ``_has_changed`` method
  370. on a widget, you should now define this method on the form field itself.
  371. ``module_name`` model meta attribute
  372. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  373. ``Model._meta.module_name`` was renamed to ``model_name``. Despite being a
  374. private API, it will go through a regular deprecation path.
  375. ``get_query_set`` and similar methods renamed to ``get_queryset``
  376. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  377. Methods that return a ``QuerySet`` such as ``Manager.get_query_set`` or
  378. ``ModelAdmin.queryset`` have been renamed to ``get_queryset``.
  379. ``shortcut`` view and URLconf
  380. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  381. The ``shortcut`` view was moved from ``django.views.defaults`` to
  382. ``django.contrib.contenttypes.views`` shortly after the 1.0 release, but the
  383. old location was never deprecated. This oversight was corrected in Django 1.6
  384. and you should now use the new location.
  385. The URLconf ``django.conf.urls.shortcut`` was also deprecated. If you're
  386. including it in an URLconf, simply replace::
  387. (r'^prefix/', include('django.conf.urls.shortcut')),
  388. with::
  389. (r'^prefix/(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'django.contrib.contenttypes.views.shortcut'),
  390. ``ModelForm`` without ``fields`` or ``exclude``
  391. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  392. Previously, if you wanted a :class:`~django.forms.ModelForm` to use all fields on
  393. the model, you could simply omit the ``Meta.fields`` attribute, and all fields
  394. would be used.
  395. This can lead to security problems where fields are added to the model and,
  396. unintentionally, automatically become editable by end users. In some cases,
  397. particular with boolean fields, it is possible for this problem to be completely
  398. invisible. This is a form of `Mass assignment vulnerability
  399. <http://en.wikipedia.org/wiki/Mass_assignment_vulnerability>`_.
  400. For this reason, this behaviour is deprecated, and using the ``Meta.exclude``
  401. option is strongly discouraged. Instead, all fields that are intended for
  402. inclusion in the form should be listed explicitly in the ``fields`` attribute.
  403. If this security concern really does not apply in your case, there is a shortcut
  404. to explicitly indicate that all fields should be used - use the special value
  405. ``"__all__"`` for the fields attribute::
  406. class MyModelForm(ModelForm):
  407. class Meta:
  408. fields = "__all__"
  409. model = MyModel
  410. If you have custom ``ModelForms`` that only need to be used in the admin, there
  411. is another option. The admin has its own methods for defining fields
  412. (``fieldsets`` etc.), and so adding a list of fields to the ``ModelForm`` is
  413. redundant. Instead, simply omit the ``Meta`` inner class of the ``ModelForm``,
  414. or omit the ``Meta.model`` attribute. Since the ``ModelAdmin`` subclass knows
  415. which model it is for, it can add the necessary attributes to derive a
  416. functioning ``ModelForm``. This behaviour also works for earlier Django
  417. versions.
  418. ``UpdateView`` and ``CreateView`` without explicit fields
  419. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  420. The generic views :class:`~django.views.generic.edit.CreateView` and
  421. :class:`~django.views.generic.edit.UpdateView`, and anything else derived from
  422. :class:`~django.views.generic.edit.ModelFormMixin`, are vulnerable to the
  423. security problem described in the section above, because they can automatically
  424. create a ``ModelForm`` that uses all fields for a model.
  425. For this reason, if you use these views for editing models, you must also supply
  426. the ``fields`` attribute, which is a list of model fields and works in the same
  427. way as the :class:`~django.forms.ModelForm` ``Meta.fields`` attribute. Alternatively,
  428. you can set set the ``form_class`` attribute to a ``ModelForm`` that explicitly
  429. defines the fields to be used. Defining an ``UpdateView`` or ``CreateView``
  430. subclass to be used with a model but without an explicit list of fields is
  431. deprecated.