1. ========================
    
  2. Django 1.8 release notes
    
  3. ========================
    
  4. 
    
  5. *April 1, 2015*
    
  6. 
    
  7. Welcome to Django 1.8!
    
  8. 
    
  9. These release notes cover the :ref:`new features <whats-new-1.8>`, as well as
    
  10. some :ref:`backwards incompatible changes <backwards-incompatible-1.8>` you'll
    
  11. want to be aware of when upgrading from Django 1.7 or older versions. We've
    
  12. also :ref:`begun the deprecation process for some features
    
  13. <deprecated-features-1.8>`, and some features have reached the end of their
    
  14. deprecation process and :ref:`have been removed <removed-features-1.8>`.
    
  15. 
    
  16. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
    
  17. project.
    
  18. 
    
  19. Django 1.8 has been designated as Django's second :term:`long-term support
    
  20. release <Long-term support release>`. It will receive security updates for at
    
  21. least three years after its release. Support for the previous LTS, Django 1.4,
    
  22. will end 6 months from the release date of Django 1.8.
    
  23. 
    
  24. Python compatibility
    
  25. ====================
    
  26. 
    
  27. Django 1.8 requires Python 2.7, 3.2, 3.3, 3.4, or 3.5. We **highly recommend**
    
  28. and only officially support the latest release of each series.
    
  29. 
    
  30. Django 1.8 is the first release to support Python 3.5.
    
  31. 
    
  32. Due to the end of upstream support for Python 3.2 in February 2016, we won't
    
  33. test Django 1.8.x on Python 3.2 after the end of 2016.
    
  34. 
    
  35. .. _whats-new-1.8:
    
  36. 
    
  37. What's new in Django 1.8
    
  38. ========================
    
  39. 
    
  40. ``Model._meta`` API
    
  41. -------------------
    
  42. 
    
  43. Django now has a formalized API for :doc:`Model._meta </ref/models/meta>`,
    
  44. providing an officially supported way to :ref:`retrieve fields
    
  45. <model-meta-field-api>` and filter fields based on their :ref:`attributes
    
  46. <model-field-attributes>`.
    
  47. 
    
  48. The ``Model._meta`` object has been part of Django since the days of pre-0.96
    
  49. "Magic Removal" -- it just wasn't an official, stable API. In recognition of
    
  50. this, we've endeavored to maintain backwards-compatibility with the old
    
  51. API endpoint where possible. However, API endpoints that aren't part of the
    
  52. new official API have been deprecated and will eventually be removed.
    
  53. 
    
  54. Multiple template engines
    
  55. -------------------------
    
  56. 
    
  57. Django 1.8 defines a stable API for integrating template backends. It includes
    
  58. built-in support for the Django template language and for
    
  59. :class:`~django.template.backends.jinja2.Jinja2`. It supports rendering
    
  60. templates with multiple engines within the same project. Learn more about the
    
  61. new features in the :doc:`topic guide </topics/templates>` and check the
    
  62. upgrade instructions in older versions of the documentation.
    
  63. 
    
  64. Security enhancements
    
  65. ---------------------
    
  66. 
    
  67. Several features of the django-secure_ third-party library have been
    
  68. integrated into Django. :class:`django.middleware.security.SecurityMiddleware`
    
  69. provides several security enhancements to the request/response cycle. The new
    
  70. :option:`check --deploy` option allows you to check your production settings
    
  71. file for ways to increase the security of your site.
    
  72. 
    
  73. .. _django-secure: https://pypi.org/project/django-secure/
    
  74. 
    
  75. New PostgreSQL specific functionality
    
  76. -------------------------------------
    
  77. 
    
  78. Django now has a module with extensions for PostgreSQL specific features, such
    
  79. as :class:`~django.contrib.postgres.fields.ArrayField`,
    
  80. :class:`~django.contrib.postgres.fields.HStoreField`, :ref:`range-fields`, and
    
  81. :lookup:`unaccent` lookup. A full breakdown of the features is available
    
  82. :doc:`in the documentation </ref/contrib/postgres/index>`.
    
  83. 
    
  84. New data types
    
  85. --------------
    
  86. 
    
  87. * Django now has a :class:`~django.db.models.UUIDField` for storing
    
  88.   universally unique identifiers. It is stored as the native ``uuid`` data type
    
  89.   on PostgreSQL and as a fixed length character field on other backends. There
    
  90.   is a corresponding :class:`form field <django.forms.UUIDField>`.
    
  91. 
    
  92. * Django now has a :class:`~django.db.models.DurationField` for storing periods
    
  93.   of time - modeled in Python by :class:`~python:datetime.timedelta`. It is
    
  94.   stored in the native ``interval`` data type on PostgreSQL, as a ``INTERVAL
    
  95.   DAY(9) TO SECOND(6)`` on Oracle, and as a ``bigint`` of microseconds on other
    
  96.   backends. Date and time related arithmetic has also been improved on all
    
  97.   backends. There is a corresponding :class:`form field
    
  98.   <django.forms.DurationField>`.
    
  99. 
    
  100. Query Expressions, Conditional Expressions, and Database Functions
    
  101. ------------------------------------------------------------------
    
  102. 
    
  103. :doc:`Query Expressions </ref/models/expressions>` allow you to create,
    
  104. customize, and compose complex SQL expressions. This has enabled annotate
    
  105. to accept expressions other than aggregates. Aggregates are now able to
    
  106. reference multiple fields, as well as perform arithmetic, similar to ``F()``
    
  107. objects. :meth:`~django.db.models.query.QuerySet.order_by` has also gained the
    
  108. ability to accept expressions.
    
  109. 
    
  110. :doc:`Conditional Expressions </ref/models/conditional-expressions>` allow
    
  111. you to use :keyword:`if` ... :keyword:`elif` ... :keyword:`else` logic within
    
  112. queries.
    
  113. 
    
  114. A collection of :doc:`database functions </ref/models/database-functions>` is
    
  115. also included with functionality such as
    
  116. :class:`~django.db.models.functions.Coalesce`,
    
  117. :class:`~django.db.models.functions.Concat`, and
    
  118. :class:`~django.db.models.functions.Substr`.
    
  119. 
    
  120. ``TestCase`` data setup
    
  121. -----------------------
    
  122. 
    
  123. :class:`~django.test.TestCase` has been refactored to allow for data
    
  124. initialization at the class level using transactions and savepoints. Database
    
  125. backends which do not support transactions, like MySQL with the MyISAM storage
    
  126. engine, will still be able to run these tests but won't benefit from the
    
  127. improvements. Tests are now run within two nested
    
  128. :func:`~django.db.transaction.atomic()` blocks: one for the whole class and one
    
  129. for each test.
    
  130. 
    
  131. * The class method
    
  132.   :meth:`TestCase.setUpTestData() <django.test.TestCase.setUpTestData>` adds
    
  133.   the ability to set up test data at the class level. Using this technique can
    
  134.   speed up the tests as compared to using ``setUp()``.
    
  135. 
    
  136. * Fixture loading within ``TestCase`` is now performed once for the whole
    
  137.   ``TestCase``.
    
  138. 
    
  139. Minor features
    
  140. --------------
    
  141. 
    
  142. :mod:`django.contrib.admin`
    
  143. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  144. 
    
  145. * :class:`~django.contrib.admin.ModelAdmin` now has a
    
  146.   :meth:`~django.contrib.admin.ModelAdmin.has_module_permission`
    
  147.   method to allow limiting access to the module on the admin index page.
    
  148. 
    
  149. * :class:`~django.contrib.admin.InlineModelAdmin` now has an attribute
    
  150.   :attr:`~django.contrib.admin.InlineModelAdmin.show_change_link` that
    
  151.   supports showing a link to an inline object's change form.
    
  152. 
    
  153. * Use the new ``django.contrib.admin.RelatedOnlyFieldListFilter`` in
    
  154.   :attr:`ModelAdmin.list_filter <django.contrib.admin.ModelAdmin.list_filter>`
    
  155.   to limit the ``list_filter`` choices to foreign objects which are attached to
    
  156.   those from the ``ModelAdmin``.
    
  157. 
    
  158. * The :meth:`ModelAdmin.delete_view()
    
  159.   <django.contrib.admin.ModelAdmin.delete_view>` displays a summary of objects
    
  160.   to be deleted on the deletion confirmation page.
    
  161. 
    
  162. * The jQuery library embedded in the admin has been upgraded to version 1.11.2.
    
  163. 
    
  164. * You can now specify :attr:`AdminSite.site_url
    
  165.   <django.contrib.admin.AdminSite.site_url>` in order to display a link to the
    
  166.   front-end site.
    
  167. 
    
  168. * You can now specify :attr:`ModelAdmin.show_full_result_count
    
  169.   <django.contrib.admin.ModelAdmin.show_full_result_count>` to control whether
    
  170.   or not the full count of objects should be displayed on a filtered admin page.
    
  171. 
    
  172. * The ``AdminSite.password_change()`` method now has an ``extra_context``
    
  173.   parameter.
    
  174. 
    
  175. * You can now control who may login to the admin site by overriding only
    
  176.   :meth:`AdminSite.has_permission()
    
  177.   <django.contrib.admin.AdminSite.has_permission>` and
    
  178.   :attr:`AdminSite.login_form <django.contrib.admin.AdminSite.login_form>`.
    
  179.   The ``base.html`` template has a new block ``usertools`` which contains the
    
  180.   user-specific header. A new context variable ``has_permission``, which gets
    
  181.   its value from :meth:`~django.contrib.admin.AdminSite.has_permission`,
    
  182.   indicates whether the user may access the site.
    
  183. 
    
  184. * Foreign key dropdowns now have buttons for changing or deleting related
    
  185.   objects using a popup.
    
  186. 
    
  187. :mod:`django.contrib.admindocs`
    
  188. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  189. 
    
  190. * reStructuredText is now parsed in model docstrings.
    
  191. 
    
  192. :mod:`django.contrib.auth`
    
  193. ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  194. 
    
  195. * Authorization backends can now raise
    
  196.   :class:`~django.core.exceptions.PermissionDenied` in
    
  197.   :meth:`~django.contrib.auth.models.User.has_perm`
    
  198.   and :meth:`~django.contrib.auth.models.User.has_module_perms`
    
  199.   to short-circuit permission checking.
    
  200. * :class:`~django.contrib.auth.forms.PasswordResetForm` now
    
  201.   has a method :meth:`~django.contrib.auth.forms.PasswordResetForm.send_mail`
    
  202.   that can be overridden to customize the mail to be sent.
    
  203. 
    
  204. * The ``max_length`` of :attr:`Permission.name
    
  205.   <django.contrib.auth.models.Permission.name>` has been increased from 50 to
    
  206.   255 characters. Please run the database migration.
    
  207. 
    
  208. * :attr:`~django.contrib.auth.models.CustomUser.USERNAME_FIELD` and
    
  209.   :attr:`~django.contrib.auth.models.CustomUser.REQUIRED_FIELDS` now supports
    
  210.   :class:`~django.db.models.ForeignKey`\s.
    
  211. 
    
  212. * The default iteration count for the PBKDF2 password hasher has been
    
  213.   increased by 33%. This backwards compatible change will not affect users who
    
  214.   have subclassed ``django.contrib.auth.hashers.PBKDF2PasswordHasher`` to
    
  215.   change the default value.
    
  216. 
    
  217. :mod:`django.contrib.gis`
    
  218. ~~~~~~~~~~~~~~~~~~~~~~~~~
    
  219. 
    
  220. * A new :doc:`GeoJSON serializer </ref/contrib/gis/serializers>` is now
    
  221.   available.
    
  222. 
    
  223. * It is now allowed to include a subquery as a geographic lookup argument, for
    
  224.   example ``City.objects.filter(point__within=Country.objects.filter(continent='Africa').values('mpoly'))``.
    
  225. 
    
  226. * The SpatiaLite backend now supports ``Collect`` and ``Extent`` aggregates
    
  227.   when the database version is 3.0 or later.
    
  228. 
    
  229. * The PostGIS 2 ``CREATE EXTENSION postgis`` and the SpatiaLite
    
  230.   ``SELECT InitSpatialMetaData`` initialization commands are now automatically
    
  231.   run by :djadmin:`migrate`.
    
  232. 
    
  233. * The GDAL interface now supports retrieving properties of
    
  234.   :ref:`raster (image) data file <raster-data-source-objects>`.
    
  235. 
    
  236. * Compatibility shims for ``SpatialRefSys`` and ``GeometryColumns`` changed in
    
  237.   Django 1.2 have been removed.
    
  238. 
    
  239. * All GDAL-related exceptions are now raised with ``GDALException``. The former
    
  240.   ``OGRException`` has been kept for backwards compatibility but should not be
    
  241.   used any longer.
    
  242. 
    
  243. :mod:`django.contrib.sessions`
    
  244. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  245. 
    
  246. * Session cookie is now deleted after
    
  247.   :meth:`~django.contrib.sessions.backends.base.SessionBase.flush()` is called.
    
  248. 
    
  249. :mod:`django.contrib.sitemaps`
    
  250. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  251. 
    
  252. * The new :attr:`Sitemap.i18n <django.contrib.sitemaps.Sitemap.i18n>` attribute
    
  253.   allows you to generate a sitemap based on the :setting:`LANGUAGES` setting.
    
  254. 
    
  255. :mod:`django.contrib.sites`
    
  256. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  257. 
    
  258. * :func:`~django.contrib.sites.shortcuts.get_current_site` will now lookup
    
  259.   the current site based on :meth:`request.get_host()
    
  260.   <django.http.HttpRequest.get_host>` if the :setting:`SITE_ID` setting is not
    
  261.   defined.
    
  262. 
    
  263. * The default :class:`~django.contrib.sites.models.Site` created when running
    
  264.   ``migrate`` now respects the :setting:`SITE_ID` setting (instead of always
    
  265.   using ``pk=1``).
    
  266. 
    
  267. Cache
    
  268. ~~~~~
    
  269. 
    
  270. * The ``incr()`` method of the
    
  271.   ``django.core.cache.backends.locmem.LocMemCache`` backend is now thread-safe.
    
  272. 
    
  273. Cryptography
    
  274. ~~~~~~~~~~~~
    
  275. 
    
  276. * The ``max_age`` parameter of the
    
  277.   :meth:`django.core.signing.TimestampSigner.unsign` method now also accepts a
    
  278.   :py:class:`datetime.timedelta` object.
    
  279. 
    
  280. Database backends
    
  281. ~~~~~~~~~~~~~~~~~
    
  282. 
    
  283. * The MySQL backend no longer strips microseconds from ``datetime`` values as
    
  284.   MySQL 5.6.4 and up supports fractional seconds depending on the declaration
    
  285.   of the datetime field (when ``DATETIME`` includes fractional precision greater
    
  286.   than 0). New datetime database columns created with Django 1.8 and MySQL 5.6.4
    
  287.   and up will support microseconds. See the :ref:`MySQL database notes
    
  288.   <mysql-fractional-seconds>` for more details.
    
  289. 
    
  290. * The MySQL backend no longer creates explicit indexes for foreign keys when
    
  291.   using the InnoDB storage engine, as MySQL already creates them automatically.
    
  292. 
    
  293. * The Oracle backend no longer defines the ``connection_persists_old_columns``
    
  294.   feature as ``True``. Instead, Oracle will now include a cache busting clause
    
  295.   when getting the description of a table.
    
  296. 
    
  297. Email
    
  298. ~~~~~
    
  299. 
    
  300. * :ref:`Email backends <topic-email-backends>` now support the context manager
    
  301.   protocol for opening and closing connections.
    
  302. 
    
  303. * The SMTP email backend now supports ``keyfile`` and ``certfile``
    
  304.   authentication with the :setting:`EMAIL_SSL_CERTFILE` and
    
  305.   :setting:`EMAIL_SSL_KEYFILE` settings.
    
  306. 
    
  307. * The SMTP :class:`~django.core.mail.backends.smtp.EmailBackend` now supports
    
  308.   setting the ``timeout`` parameter with the :setting:`EMAIL_TIMEOUT` setting.
    
  309. 
    
  310. * :class:`~django.core.mail.EmailMessage` and ``EmailMultiAlternatives`` now
    
  311.   support the ``reply_to`` parameter.
    
  312. 
    
  313. File Storage
    
  314. ~~~~~~~~~~~~
    
  315. 
    
  316. * :meth:`Storage.get_available_name()
    
  317.   <django.core.files.storage.Storage.get_available_name>` and
    
  318.   :meth:`Storage.save() <django.core.files.storage.Storage.save>`
    
  319.   now take a ``max_length`` argument to implement storage-level maximum
    
  320.   filename length constraints. Filenames exceeding this argument will get
    
  321.   truncated. This prevents a database error when appending a unique suffix to a
    
  322.   long filename that already exists on the storage. See the :ref:`deprecation
    
  323.   note <storage-max-length-update>` about adding this argument to your custom
    
  324.   storage classes.
    
  325. 
    
  326. Forms
    
  327. ~~~~~
    
  328. 
    
  329. * Form widgets now render attributes with a value of ``True`` or ``False``
    
  330.   as HTML5 boolean attributes.
    
  331. 
    
  332. * The new :meth:`~django.forms.Form.has_error()` method allows checking
    
  333.   if a specific error has happened.
    
  334. 
    
  335. * If :attr:`~django.forms.Form.required_css_class` is defined on a form, then
    
  336.   the ``<label>`` tags for required fields will have this class present in its
    
  337.   attributes.
    
  338. 
    
  339. * The rendering of non-field errors in unordered lists (``<ul>``) now includes
    
  340.   ``nonfield`` in its list of classes to distinguish them from field-specific
    
  341.   errors.
    
  342. 
    
  343. * :class:`~django.forms.Field` now accepts a
    
  344.   :attr:`~django.forms.Field.label_suffix` argument, which will override the
    
  345.   form's :attr:`~django.forms.Form.label_suffix`. This enables customizing the
    
  346.   suffix on a per-field basis — previously it wasn't possible to override
    
  347.   a form's :attr:`~django.forms.Form.label_suffix` while using  shortcuts such
    
  348.   as ``{{ form.as_p }}`` in templates.
    
  349. 
    
  350. * :class:`~django.forms.SelectDateWidget` now accepts an
    
  351.   :attr:`~django.forms.SelectDateWidget.empty_label` argument, which will
    
  352.   override the top list choice label when :class:`~django.forms.DateField`
    
  353.   is not required.
    
  354. 
    
  355. * After an :class:`~django.forms.ImageField` has been cleaned and validated, the
    
  356.   ``UploadedFile`` object will have an additional ``image`` attribute containing
    
  357.   the Pillow ``Image`` instance used to check if the file was a valid image. It
    
  358.   will also update ``UploadedFile.content_type`` with the image's content type
    
  359.   as determined by Pillow.
    
  360. 
    
  361. * You can now pass a callable that returns an iterable of choices when
    
  362.   instantiating a :class:`~django.forms.ChoiceField`.
    
  363. 
    
  364. Generic Views
    
  365. ~~~~~~~~~~~~~
    
  366. 
    
  367. * Generic views that use :class:`~django.views.generic.list.MultipleObjectMixin`
    
  368.   may now specify the ordering applied to the
    
  369.   :attr:`~django.views.generic.list.MultipleObjectMixin.queryset` by setting
    
  370.   :attr:`~django.views.generic.list.MultipleObjectMixin.ordering` or overriding
    
  371.   :meth:`~django.views.generic.list.MultipleObjectMixin.get_ordering()`.
    
  372. 
    
  373. * The new :attr:`SingleObjectMixin.query_pk_and_slug
    
  374.   <django.views.generic.detail.SingleObjectMixin.query_pk_and_slug>`
    
  375.   attribute allows changing the behavior of
    
  376.   :meth:`~django.views.generic.detail.SingleObjectMixin.get_object()`
    
  377.   so that it'll perform its lookup using both the primary key and the slug.
    
  378. 
    
  379. * The :meth:`~django.views.generic.edit.FormMixin.get_form()` method doesn't
    
  380.   require a ``form_class`` to be provided anymore. If not provided ``form_class``
    
  381.   defaults to :meth:`~django.views.generic.edit.FormMixin.get_form_class()`.
    
  382. 
    
  383. * Placeholders in :attr:`ModelFormMixin.success_url
    
  384.   <django.views.generic.edit.ModelFormMixin.success_url>` now support the Python
    
  385.   :py:meth:`str.format()` syntax. The legacy ``%(<foo>)s`` syntax is still
    
  386.   supported but will be removed in Django 1.10.
    
  387. 
    
  388. Internationalization
    
  389. ~~~~~~~~~~~~~~~~~~~~
    
  390. 
    
  391. * :setting:`FORMAT_MODULE_PATH` can now be a list of strings representing
    
  392.   module paths. This allows importing several format modules from different
    
  393.   reusable apps. It also allows overriding those custom formats in your main
    
  394.   Django project.
    
  395. 
    
  396. Logging
    
  397. ~~~~~~~
    
  398. 
    
  399. * The :class:`django.utils.log.AdminEmailHandler` class now has a
    
  400.   :meth:`~django.utils.log.AdminEmailHandler.send_mail` method to make it more
    
  401.   subclass friendly.
    
  402. 
    
  403. Management Commands
    
  404. ~~~~~~~~~~~~~~~~~~~
    
  405. 
    
  406. * Database connections are now always closed after a management command called
    
  407.   from the command line has finished doing its job.
    
  408. 
    
  409. * Commands from alternate package formats like eggs are now also discovered.
    
  410. 
    
  411. * The new :option:`dumpdata --output` option allows specifying a file to which
    
  412.   the serialized data is written.
    
  413. 
    
  414. * The new :option:`makemessages --exclude` and :option:`compilemessages
    
  415.   --exclude` options allow excluding specific locales from processing.
    
  416. 
    
  417. * :djadmin:`compilemessages` now has a ``--use-fuzzy`` or ``-f`` option which
    
  418.   includes fuzzy translations into compiled files.
    
  419. 
    
  420. * The :option:`loaddata --ignorenonexistent` option now ignores data for models
    
  421.   that no longer exist.
    
  422. 
    
  423. * :djadmin:`runserver` now uses daemon threads for faster reloading.
    
  424. 
    
  425. * :djadmin:`inspectdb` now outputs ``Meta.unique_together``. It is also able to
    
  426.   introspect :class:`~django.db.models.AutoField` for MySQL and PostgreSQL
    
  427.   databases.
    
  428. 
    
  429. * When calling management commands with options using
    
  430.   :func:`~django.core.management.call_command`, the option name can match the
    
  431.   command line option name (without the initial dashes) or the final option
    
  432.   destination variable name, but in either case, the resulting option received
    
  433.   by the command is now always the ``dest`` name specified in the command
    
  434.   option definition (as long as the command uses the :mod:`argparse` module).
    
  435. 
    
  436. * The :djadmin:`dbshell` command now supports MySQL's optional SSL certificate
    
  437.   authority setting (``--ssl-ca``).
    
  438. 
    
  439. * The new :option:`makemigrations --name` allows giving the migration(s) a
    
  440.   custom name instead of a generated one.
    
  441. 
    
  442. * The :djadmin:`loaddata` command now prevents repeated fixture loading. If
    
  443.   :setting:`FIXTURE_DIRS` contains duplicates or a default fixture directory
    
  444.   path (``app_name/fixtures``), an exception is raised.
    
  445. 
    
  446. * The new ``makemigrations --exit`` option allows exiting with an error
    
  447.   code if no migrations are created.
    
  448. 
    
  449. * The new :djadmin:`showmigrations` command allows listing all migrations and
    
  450.   their dependencies in a project.
    
  451. 
    
  452. Middleware
    
  453. ~~~~~~~~~~
    
  454. 
    
  455. * The :attr:`CommonMiddleware.response_redirect_class
    
  456.   <django.middleware.common.CommonMiddleware.response_redirect_class>`
    
  457.   attribute allows you to customize the redirects issued by the middleware.
    
  458. 
    
  459. * A debug message will be logged to the ``django.request`` logger when a
    
  460.   middleware raises a :exc:`~django.core.exceptions.MiddlewareNotUsed` exception
    
  461.   in :setting:`DEBUG` mode.
    
  462. 
    
  463. Migrations
    
  464. ~~~~~~~~~~
    
  465. 
    
  466. * The :class:`~django.db.migrations.operations.RunSQL` operation can now handle
    
  467.   parameters passed to the SQL statements.
    
  468. 
    
  469. * It is now possible to have migrations (most probably :ref:`data migrations
    
  470.   <data-migrations>`) for applications without models.
    
  471. 
    
  472. * Migrations can now :ref:`serialize model managers
    
  473.   <using-managers-in-migrations>` as part of the model state.
    
  474. 
    
  475. * A :ref:`generic mechanism to handle the deprecation of model fields
    
  476.   <migrations-removing-model-fields>` was added.
    
  477. 
    
  478. * The :meth:`RunPython.noop() <django.db.migrations.operations.RunPython.noop>`
    
  479.   and :attr:`RunSQL.noop <django.db.migrations.operations.RunSQL.noop>` class
    
  480.   method/attribute were added to ease in making ``RunPython`` and ``RunSQL``
    
  481.   operations reversible.
    
  482. 
    
  483. * The migration operations :class:`~django.db.migrations.operations.RunPython`
    
  484.   and :class:`~django.db.migrations.operations.RunSQL` now call the
    
  485.   :meth:`allow_migrate` method of database routers. The router can use the
    
  486.   newly introduced ``app_label`` and ``hints`` arguments to make a routing
    
  487.   decision. To take advantage of this feature you need to update the router to
    
  488.   the new ``allow_migrate`` signature, see the :ref:`deprecation section
    
  489.   <deprecated-signature-of-allow-migrate>` for more details.
    
  490. 
    
  491. Models
    
  492. ~~~~~~
    
  493. 
    
  494. * Django now logs at most 9000 queries in ``connections.queries``, in order
    
  495.   to prevent excessive memory usage in long-running processes in debug mode.
    
  496. 
    
  497. * There is now a model ``Meta`` option to define a
    
  498.   :attr:`default related name <django.db.models.Options.default_related_name>`
    
  499.   for all relational fields of a model.
    
  500. 
    
  501. * Pickling models and querysets across different versions of Django isn't
    
  502.   officially supported (it may work, but there's no guarantee). An extra
    
  503.   variable that specifies the current Django version is now added to the
    
  504.   pickled state of models and querysets, and Django raises a ``RuntimeWarning``
    
  505.   when these objects are unpickled in a different version than the one in
    
  506.   which they were pickled.
    
  507. 
    
  508. * Added :meth:`Model.from_db() <django.db.models.Model.from_db()>` which
    
  509.   Django uses whenever objects are loaded using the ORM. The method allows
    
  510.   customizing model loading behavior.
    
  511. 
    
  512. * ``extra(select={...})`` now allows you to escape a literal ``%s`` sequence
    
  513.   using ``%%s``.
    
  514. 
    
  515. * :doc:`Custom Lookups</howto/custom-lookups>` can now be registered using
    
  516.   a decorator pattern.
    
  517. 
    
  518. * The new :attr:`Transform.bilateral <django.db.models.Transform.bilateral>`
    
  519.   attribute allows creating bilateral transformations. These transformations
    
  520.   are applied to both ``lhs`` and ``rhs`` when used in a lookup expression,
    
  521.   providing opportunities for more sophisticated lookups.
    
  522. 
    
  523. * SQL special characters (\, %, _) are now escaped properly when a pattern
    
  524.   lookup (e.g. ``contains``, ``startswith``, etc.) is used with an ``F()``
    
  525.   expression as the right-hand side. In those cases, the escaping is performed
    
  526.   by the database, which can lead to somewhat complex queries involving nested
    
  527.   ``REPLACE`` function calls.
    
  528. 
    
  529. * You can now refresh model instances by using :meth:`Model.refresh_from_db()
    
  530.   <django.db.models.Model.refresh_from_db>`.
    
  531. 
    
  532. * You can now get the set of deferred fields for a model using
    
  533.   :meth:`Model.get_deferred_fields() <django.db.models.Model.get_deferred_fields>`.
    
  534. 
    
  535. * Model field ``default``’s are now used when primary key field's are set to
    
  536.   ``None``.
    
  537. 
    
  538. Signals
    
  539. ~~~~~~~
    
  540. 
    
  541. * Exceptions from the ``(receiver, exception)`` tuples returned by
    
  542.   :meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
    
  543.   their traceback attached as a ``__traceback__`` attribute.
    
  544. 
    
  545. * The ``environ`` argument, which contains the WSGI environment structure from
    
  546.   the request, was added to the :data:`~django.core.signals.request_started`
    
  547.   signal.
    
  548. 
    
  549. * You can now import the :func:`~django.test.signals.setting_changed` signal
    
  550.   from ``django.core.signals`` to avoid loading ``django.test`` in non-test
    
  551.   situations. Django no longer does so itself.
    
  552. 
    
  553. System Check Framework
    
  554. ~~~~~~~~~~~~~~~~~~~~~~
    
  555. 
    
  556. * :attr:`~django.core.checks.register` can now be used as a function.
    
  557. 
    
  558. Templates
    
  559. ~~~~~~~~~
    
  560. 
    
  561. * :tfilter:`urlize` now supports domain-only links that include characters after
    
  562.   the top-level domain (e.g. ``djangoproject.com/`` and
    
  563.   ``djangoproject.com/download/``).
    
  564. 
    
  565. * :tfilter:`urlize` doesn't treat exclamation marks at the end of a domain or
    
  566.   its query string as part of the URL (the URL in e.g. ``'djangoproject.com!``
    
  567.   is ``djangoproject.com``)
    
  568. 
    
  569. * Added a :class:`locmem.Loader <django.template.loaders.locmem.Loader>`
    
  570.   class that loads Django templates from a Python dictionary.
    
  571. 
    
  572. * The :ttag:`now` tag can now store its output in a context variable with the
    
  573.   usual syntax: ``{% now 'j n Y' as varname %}``.
    
  574. 
    
  575. Requests and Responses
    
  576. ~~~~~~~~~~~~~~~~~~~~~~
    
  577. 
    
  578. * ``WSGIRequest`` now respects paths starting with ``//``.
    
  579. 
    
  580. * The :meth:`HttpRequest.build_absolute_uri()
    
  581.   <django.http.HttpRequest.build_absolute_uri>` method now handles paths
    
  582.   starting with ``//`` correctly.
    
  583. 
    
  584. * If :setting:`DEBUG` is ``True`` and a request raises a
    
  585.   :exc:`~django.core.exceptions.SuspiciousOperation`, the response will be
    
  586.   rendered with a detailed error page.
    
  587. 
    
  588. * The ``query_string`` argument of :class:`~django.http.QueryDict` is now
    
  589.   optional, defaulting to ``None``, so a blank ``QueryDict`` can now be
    
  590.   instantiated with ``QueryDict()`` instead of ``QueryDict(None)`` or
    
  591.   ``QueryDict('')``.
    
  592. 
    
  593. * The ``GET`` and ``POST`` attributes of an :class:`~django.http.HttpRequest`
    
  594.   object are now :class:`~django.http.QueryDict`\s rather than dictionaries,
    
  595.   and the ``FILES`` attribute is now a ``MultiValueDict``.
    
  596.   This brings this class into line with the documentation and with
    
  597.   ``WSGIRequest``.
    
  598. 
    
  599. * The :attr:`HttpResponse.charset <django.http.HttpResponse.charset>` attribute
    
  600.   was added.
    
  601. 
    
  602. * ``WSGIRequestHandler`` now follows RFC in converting URI to IRI, using
    
  603.   ``uri_to_iri()``.
    
  604. 
    
  605. * The :meth:`HttpRequest.get_full_path()
    
  606.   <django.http.HttpRequest.get_full_path>` method now escapes unsafe characters
    
  607.   from the path portion of a Uniform Resource Identifier (URI) properly.
    
  608. 
    
  609. * :class:`~django.http.HttpResponse` now implements a few additional methods
    
  610.   like :meth:`~django.http.HttpResponse.getvalue` so that instances can be used
    
  611.   as stream objects.
    
  612. 
    
  613. * The new :meth:`HttpResponse.setdefault()
    
  614.   <django.http.HttpResponse.setdefault>` method allows setting a header unless
    
  615.   it has already been set.
    
  616. 
    
  617. * You can use the new :class:`~django.http.FileResponse` to stream files.
    
  618. 
    
  619. * The :func:`~django.views.decorators.http.condition` decorator for
    
  620.   conditional view processing now supports the ``If-unmodified-since`` header.
    
  621. 
    
  622. Tests
    
  623. ~~~~~
    
  624. 
    
  625. * The :class:`RequestFactory.trace() <django.test.RequestFactory>`
    
  626.   and :class:`Client.trace() <django.test.Client.trace>` methods were
    
  627.   implemented, allowing you to create ``TRACE`` requests in your tests.
    
  628. 
    
  629. * The ``count`` argument was added to
    
  630.   :meth:`~django.test.SimpleTestCase.assertTemplateUsed`. This allows you to
    
  631.   assert that a template was rendered a specific number of times.
    
  632. 
    
  633. * The new :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` assertion
    
  634.   allows you to test that two JSON fragments are not equal.
    
  635. 
    
  636. * Added options to the :djadmin:`test` command to preserve the test database
    
  637.   (:option:`--keepdb <test --keepdb>`), to run the test cases in reverse order
    
  638.   (:option:`--reverse <test --reverse>`), and to enable SQL logging for failing
    
  639.   tests (:option:`--debug-sql <test --debug-sql>`).
    
  640. 
    
  641. * Added the :attr:`~django.test.Response.resolver_match` attribute to test
    
  642.   client responses.
    
  643. 
    
  644. * Added several settings that allow customization of test tablespace parameters
    
  645.   for Oracle: :setting:`DATAFILE`, :setting:`DATAFILE_TMP`,
    
  646.   :setting:`DATAFILE_MAXSIZE` and :setting:`DATAFILE_TMP_MAXSIZE`.
    
  647. 
    
  648. * The :func:`~django.test.override_settings` decorator can now affect the
    
  649.   master router in :setting:`DATABASE_ROUTERS`.
    
  650. 
    
  651. * Added test client support for file uploads with file-like objects.
    
  652. 
    
  653. * A shared cache is now used when testing with an SQLite in-memory database when
    
  654.   using Python 3.4+ and SQLite 3.7.13+. This allows sharing the database
    
  655.   between threads.
    
  656. 
    
  657. Validators
    
  658. ~~~~~~~~~~
    
  659. 
    
  660. * :class:`~django.core.validators.URLValidator` now supports IPv6 addresses,
    
  661.   Unicode domains, and URLs containing authentication data.
    
  662. 
    
  663. .. _backwards-incompatible-1.8:
    
  664. 
    
  665. Backwards incompatible changes in 1.8
    
  666. =====================================
    
  667. 
    
  668. .. warning::
    
  669. 
    
  670.     In addition to the changes outlined in this section, be sure to review the
    
  671.     :ref:`deprecation plan <deprecation-removed-in-1.8>` for any features that
    
  672.     have been removed. If you haven't updated your code within the
    
  673.     deprecation timeline for a given feature, its removal may appear as a
    
  674.     backwards incompatible change.
    
  675. 
    
  676. Related object operations are run in a transaction
    
  677. --------------------------------------------------
    
  678. 
    
  679. Some operations on related objects such as
    
  680. :meth:`~django.db.models.fields.related.RelatedManager.add()` or direct
    
  681. assignment ran multiple data modifying queries without wrapping them in
    
  682. transactions. To reduce the risk of data corruption, all data modifying methods
    
  683. that affect multiple related objects (i.e. ``add()``, ``remove()``,
    
  684. ``clear()``, and direct assignment) now perform their data modifying queries
    
  685. from within a transaction, provided your database supports transactions.
    
  686. 
    
  687. This has one backwards incompatible side effect, signal handlers triggered from
    
  688. these methods are now executed within the method's transaction and any
    
  689. exception in a signal handler will prevent the whole operation.
    
  690. 
    
  691. .. _unsaved-model-instance-check-18:
    
  692. 
    
  693. Assigning unsaved objects to relations raises an error
    
  694. ------------------------------------------------------
    
  695. 
    
  696. .. note::
    
  697. 
    
  698.     To more easily allow in-memory usage of models, this change was reverted in
    
  699.     Django 1.8.4 and replaced with a check during ``model.save()``. For example::
    
  700. 
    
  701.         >>> book = Book.objects.create(name="Django")
    
  702.         >>> book.author = Author(name="John")
    
  703.         >>> book.save()
    
  704.         Traceback (most recent call last):
    
  705.         ...
    
  706.         ValueError: save() prohibited to prevent data loss due to unsaved related object 'author'.
    
  707. 
    
  708.     A similar check on assignment to reverse one-to-one relations was removed
    
  709.     in Django 1.8.5.
    
  710. 
    
  711. Assigning unsaved objects to a :class:`~django.db.models.ForeignKey`,
    
  712. :class:`~django.contrib.contenttypes.fields.GenericForeignKey`, and
    
  713. :class:`~django.db.models.OneToOneField` now raises a :exc:`ValueError`.
    
  714. 
    
  715. Previously, the assignment of an unsaved object would be silently ignored.
    
  716. For example::
    
  717. 
    
  718.     >>> book = Book.objects.create(name="Django")
    
  719.     >>> book.author = Author(name="John")
    
  720.     >>> book.author.save()
    
  721.     >>> book.save()
    
  722. 
    
  723.     >>> Book.objects.get(name="Django")
    
  724.     >>> book.author
    
  725.     >>>
    
  726. 
    
  727. Now, an error will be raised to prevent data loss::
    
  728. 
    
  729.     >>> book.author = Author(name="john")
    
  730.     Traceback (most recent call last):
    
  731.     ...
    
  732.     ValueError: Cannot assign "<Author: John>": "Author" instance isn't saved in the database.
    
  733. 
    
  734. If you require allowing the assignment of unsaved instances (the old behavior)
    
  735. and aren't concerned about the data loss possibility (e.g. you never save the
    
  736. objects to the database), you can disable this check by using the
    
  737. ``ForeignKey.allow_unsaved_instance_assignment`` attribute. (This attribute was
    
  738. removed in 1.8.4 as it's no longer relevant.)
    
  739. 
    
  740. Management commands that only accept positional arguments
    
  741. ---------------------------------------------------------
    
  742. 
    
  743. If you have written a custom management command that only accepts positional
    
  744. arguments and you didn't specify the ``args`` command variable, you might get
    
  745. an error like ``Error: unrecognized arguments: ...``, as variable parsing is
    
  746. now based on :py:mod:`argparse` which doesn't implicitly accept positional
    
  747. arguments. You can make your command backwards compatible by simply setting the
    
  748. ``args`` class variable. However, if you don't have to keep compatibility with
    
  749. older Django versions, it's better to implement the new
    
  750. :meth:`~django.core.management.BaseCommand.add_arguments` method as described
    
  751. in :doc:`/howto/custom-management-commands`.
    
  752. 
    
  753. Custom test management command arguments through test runner
    
  754. ------------------------------------------------------------
    
  755. 
    
  756. The method to add custom arguments to the ``test`` management command through
    
  757. the test runner has changed. Previously, you could provide an ``option_list``
    
  758. class variable on the test runner to add more arguments (à la
    
  759. :py:mod:`optparse`). Now to implement the same behavior, you have to create an
    
  760. ``add_arguments(cls, parser)`` class method on the test runner and call
    
  761. ``parser.add_argument`` to add any custom arguments, as parser is now an
    
  762. :py:class:`argparse.ArgumentParser` instance.
    
  763. 
    
  764. Model check ensures auto-generated column names are within limits specified by database
    
  765. ---------------------------------------------------------------------------------------
    
  766. 
    
  767. A field name that's longer than the column name length supported by a database
    
  768. can create problems. For example, with MySQL you'll get an exception trying to
    
  769. create the column, and with PostgreSQL the column name is truncated by the
    
  770. database (you may see a warning in the PostgreSQL logs).
    
  771. 
    
  772. A model check has been introduced to better alert users to this scenario before
    
  773. the actual creation of database tables.
    
  774. 
    
  775. If you have an existing model where this check seems to be a false positive,
    
  776. for example on PostgreSQL where the name was already being truncated, simply
    
  777. use :attr:`~django.db.models.Field.db_column` to specify the name that's being
    
  778. used.
    
  779. 
    
  780. The check also applies to the columns generated in an implicit
    
  781. ``ManyToManyField.through`` model. If you run into an issue there, use
    
  782. :attr:`~django.db.models.ManyToManyField.through` to create an explicit model
    
  783. and then specify :attr:`~django.db.models.Field.db_column` on its column(s)
    
  784. as needed.
    
  785. 
    
  786. Query relation lookups now check object types
    
  787. ---------------------------------------------
    
  788. 
    
  789. Querying for model lookups now checks if the object passed is of correct type
    
  790. and raises a :exc:`ValueError` if not. Previously, Django didn't care if the
    
  791. object was of correct type; it just used the object's related field attribute
    
  792. (e.g. ``id``) for the lookup. Now, an error is raised to prevent incorrect
    
  793. lookups::
    
  794. 
    
  795.     >>> book = Book.objects.create(name="Django")
    
  796.     >>> book = Book.objects.filter(author=book)
    
  797.     Traceback (most recent call last):
    
  798.     ...
    
  799.     ValueError: Cannot query "<Book: Django>": Must be "Author" instance.
    
  800. 
    
  801. ``select_related()`` now checks given fields
    
  802. --------------------------------------------
    
  803. 
    
  804. ``select_related()`` now validates that the given fields actually exist.
    
  805. Previously, nonexistent fields were silently ignored. Now, an error is raised::
    
  806. 
    
  807.     >>> book = Book.objects.select_related('nonexistent_field')
    
  808.     Traceback (most recent call last):
    
  809.     ...
    
  810.     FieldError: Invalid field name(s) given in select_related: 'nonexistent_field'
    
  811. 
    
  812. The validation also makes sure that the given field is relational::
    
  813. 
    
  814.     >>> book = Book.objects.select_related('name')
    
  815.     Traceback (most recent call last):
    
  816.     ...
    
  817.     FieldError: Non-relational field given in select_related: 'name'
    
  818. 
    
  819. Default ``EmailField.max_length`` increased to 254
    
  820. --------------------------------------------------
    
  821. 
    
  822. The old default 75 character ``max_length`` was not capable of storing all
    
  823. possible RFC3696/5321-compliant email addresses. In order to store all
    
  824. possible valid email addresses, the ``max_length`` has been increased to 254
    
  825. characters. You will need to generate and apply database migrations for your
    
  826. affected models (or add ``max_length=75`` if you wish to keep the length on
    
  827. your current fields). A migration for
    
  828. :attr:`django.contrib.auth.models.User.email` is included.
    
  829. 
    
  830. Support for PostgreSQL versions older than 9.0
    
  831. ----------------------------------------------
    
  832. 
    
  833. The end of upstream support periods was reached in July 2014 for PostgreSQL 8.4.
    
  834. As a consequence, Django 1.8 sets 9.0 as the minimum PostgreSQL version it
    
  835. officially supports.
    
  836. 
    
  837. This also includes dropping support for PostGIS 1.3 and 1.4 as these versions
    
  838. are not supported on versions of PostgreSQL later than 8.4.
    
  839. 
    
  840. Django also now requires the use of Psycopg2 version 2.4.5 or higher (or 2.5+
    
  841. if you want to use :mod:`django.contrib.postgres`).
    
  842. 
    
  843. Support for MySQL versions older than 5.5
    
  844. -----------------------------------------
    
  845. 
    
  846. The end of upstream support periods was reached in January 2012 for MySQL 5.0
    
  847. and December 2013 for MySQL 5.1. As a consequence, Django 1.8 sets 5.5 as the
    
  848. minimum MySQL version it officially supports.
    
  849. 
    
  850. Support for Oracle versions older than 11.1
    
  851. -------------------------------------------
    
  852. 
    
  853. The end of upstream support periods was reached in July 2010 for Oracle 9.2,
    
  854. January 2012 for Oracle 10.1, and July 2013 for Oracle 10.2. As a consequence,
    
  855. Django 1.8 sets 11.1 as the minimum Oracle version it officially supports.
    
  856. 
    
  857. Specific privileges used instead of roles for tests on Oracle
    
  858. -------------------------------------------------------------
    
  859. 
    
  860. Earlier versions of Django granted the CONNECT and RESOURCE roles to the test
    
  861. user on Oracle. These roles have been deprecated, so Django 1.8 uses the
    
  862. specific underlying privileges instead. This changes the privileges required
    
  863. of the main user for running tests (unless the project is configured to avoid
    
  864. creating a test user). The exact privileges required now are detailed in
    
  865. :ref:`Oracle notes <oracle-notes>`.
    
  866. 
    
  867. ``AbstractUser.last_login`` allows null values
    
  868. ----------------------------------------------
    
  869. 
    
  870. The :attr:`AbstractUser.last_login <django.contrib.auth.models.User.last_login>`
    
  871. field now allows null values. Previously, it defaulted to the time when the user
    
  872. was created which was misleading if the user never logged in. If you are using
    
  873. the default user (:class:`django.contrib.auth.models.User`), run the database
    
  874. migration included in ``contrib.auth``.
    
  875. 
    
  876. If you are using a custom user model that inherits from ``AbstractUser``,
    
  877. you'll need to run :djadmin:`makemigrations` and generate a migration for your
    
  878. app that contains that model. Also, if wish to set ``last_login`` to ``NULL``
    
  879. for users who haven't logged in, you can run this query::
    
  880. 
    
  881.     from django.db import models
    
  882.     from django.contrib.auth import get_user_model
    
  883.     from django.contrib.auth.models import AbstractBaseUser
    
  884. 
    
  885.     UserModel = get_user_model()
    
  886.     if issubclass(UserModel, AbstractBaseUser):
    
  887.         UserModel._default_manager.filter(
    
  888.             last_login=models.F('date_joined')
    
  889.         ).update(last_login=None)
    
  890. 
    
  891. :mod:`django.contrib.gis`
    
  892. -------------------------
    
  893. 
    
  894. * Support for GEOS 3.1 and GDAL 1.6 has been dropped.
    
  895. 
    
  896. * Support for SpatiaLite < 2.4 has been dropped.
    
  897. 
    
  898. * GIS-specific lookups have been refactored to use the
    
  899.   :class:`django.db.models.Lookup` API.
    
  900. 
    
  901. * The default ``str`` representation of
    
  902.   :class:`~django.contrib.gis.geos.GEOSGeometry` objects has been changed from
    
  903.   WKT to EWKT format (including the SRID). As this representation is used in
    
  904.   the serialization framework, that means that ``dumpdata`` output will now
    
  905.   contain the SRID value of geometry objects.
    
  906. 
    
  907. Priority of context processors for ``TemplateResponse`` brought in line with ``render``
    
  908. ---------------------------------------------------------------------------------------
    
  909. 
    
  910. The :class:`~django.template.response.TemplateResponse` constructor is designed to be a
    
  911. drop-in replacement for the :func:`~django.shortcuts.render` function. However,
    
  912. it had a slight incompatibility, in that for ``TemplateResponse``, context data
    
  913. from the passed in context dictionary could be shadowed by context data returned
    
  914. from context processors, whereas for ``render`` it was the other way
    
  915. around. This was a bug, and the behavior of ``render`` is more appropriate,
    
  916. since it allows the globally defined context processors to be overridden locally
    
  917. in the view. If you were relying on the fact context data in a
    
  918. ``TemplateResponse`` could be overridden using a context processor, you will
    
  919. need to change your code.
    
  920. 
    
  921. Overriding ``setUpClass`` / ``tearDownClass`` in test cases
    
  922. -----------------------------------------------------------
    
  923. 
    
  924. The decorators :func:`~django.test.override_settings` and
    
  925. :func:`~django.test.modify_settings` now act at the class level when used as
    
  926. class decorators. As a consequence, when overriding ``setUpClass()`` or
    
  927. ``tearDownClass()``, the ``super`` implementation should always be called.
    
  928. 
    
  929. Removal of ``django.contrib.formtools``
    
  930. ---------------------------------------
    
  931. 
    
  932. The formtools contrib app has been moved to a separate package and the
    
  933. relevant documentation pages have been updated or removed.
    
  934. 
    
  935. The new package is available `on GitHub`_ and on PyPI.
    
  936. 
    
  937. .. _on GitHub: https://github.com/jazzband/django-formtools/
    
  938. 
    
  939. Database connection reloading between tests
    
  940. -------------------------------------------
    
  941. 
    
  942. Django previously closed database connections between each test within a
    
  943. ``TestCase``. This is no longer the case as Django now wraps the whole
    
  944. ``TestCase`` within a transaction. If some of your tests relied on the old
    
  945. behavior, you should have them inherit from ``TransactionTestCase`` instead.
    
  946. 
    
  947. Cleanup of the ``django.template`` namespace
    
  948. --------------------------------------------
    
  949. 
    
  950. If you've been relying on private APIs exposed in the ``django.template``
    
  951. module, you may have to import them from ``django.template.base`` instead.
    
  952. 
    
  953. Also private APIs ``django.template.base.compile_string()``,
    
  954. ``django.template.loader.find_template()``, and
    
  955. ``django.template.loader.get_template_from_string()`` were removed.
    
  956. 
    
  957. ``model`` attribute on private model relations
    
  958. ----------------------------------------------
    
  959. 
    
  960. In earlier versions of Django, on a model with a reverse foreign key
    
  961. relationship (for example), ``model._meta.get_all_related_objects()`` returned
    
  962. the relationship as a ``django.db.models.related.RelatedObject`` with the
    
  963. ``model`` attribute set to the source of the relationship. Now, this method
    
  964. returns the relationship as ``django.db.models.fields.related.ManyToOneRel``
    
  965. (private API ``RelatedObject`` has been removed), and the ``model`` attribute
    
  966. is set to the target of the relationship instead of the source. The source
    
  967. model is accessible on the ``related_model`` attribute instead.
    
  968. 
    
  969. Consider this example from the tutorial in Django 1.8::
    
  970. 
    
  971.     >>> p = Poll.objects.get(pk=1)
    
  972.     >>> p._meta.get_all_related_objects()
    
  973.     [<ManyToOneRel: polls.choice>]
    
  974.     >>> p._meta.get_all_related_objects()[0].model
    
  975.     <class 'polls.models.Poll'>
    
  976.     >>> p._meta.get_all_related_objects()[0].related_model
    
  977.     <class 'polls.models.Choice'>
    
  978. 
    
  979. and compare it to the behavior on older versions::
    
  980. 
    
  981.     >>> p._meta.get_all_related_objects()
    
  982.     [<RelatedObject: polls:choice related to poll>]
    
  983.     >>> p._meta.get_all_related_objects()[0].model
    
  984.     <class 'polls.models.Choice'>
    
  985. 
    
  986. To access the source model, you can use a pattern like this to write code that
    
  987. will work with both Django 1.8 and older versions::
    
  988. 
    
  989.     for relation in opts.get_all_related_objects():
    
  990.         to_model = getattr(relation, 'related_model', relation.model)
    
  991. 
    
  992. Also note that ``get_all_related_objects()`` is deprecated in 1.8.
    
  993. 
    
  994. Database backend API
    
  995. --------------------
    
  996. 
    
  997. The following changes to the database backend API are documented to assist
    
  998. those writing third-party backends in updating their code:
    
  999. 
    
  1000. * ``BaseDatabaseXXX`` classes have been moved to ``django.db.backends.base``.
    
  1001.   Please import them from the new locations::
    
  1002. 
    
  1003.     from django.db.backends.base.base import BaseDatabaseWrapper
    
  1004.     from django.db.backends.base.client import BaseDatabaseClient
    
  1005.     from django.db.backends.base.creation import BaseDatabaseCreation
    
  1006.     from django.db.backends.base.features import BaseDatabaseFeatures
    
  1007.     from django.db.backends.base.introspection import BaseDatabaseIntrospection
    
  1008.     from django.db.backends.base.introspection import FieldInfo, TableInfo
    
  1009.     from django.db.backends.base.operations import BaseDatabaseOperations
    
  1010.     from django.db.backends.base.schema import BaseDatabaseSchemaEditor
    
  1011.     from django.db.backends.base.validation import BaseDatabaseValidation
    
  1012. 
    
  1013. * The ``data_types``, ``data_types_suffix``, and
    
  1014.   ``data_type_check_constraints`` attributes have moved from the
    
  1015.   ``DatabaseCreation`` class to ``DatabaseWrapper``.
    
  1016. 
    
  1017. * The ``SQLCompiler.as_sql()`` method now takes a ``subquery`` parameter
    
  1018.   (:ticket:`24164`).
    
  1019. 
    
  1020. * The ``BaseDatabaseOperations.date_interval_sql()`` method now only takes a
    
  1021.   ``timedelta`` parameter.
    
  1022. 
    
  1023. :mod:`django.contrib.admin`
    
  1024. ---------------------------
    
  1025. 
    
  1026. * ``AdminSite`` no longer takes an ``app_name`` argument and its ``app_name``
    
  1027.   attribute has been removed. The application name is always ``admin`` (as
    
  1028.   opposed to the instance name which you can still customize using
    
  1029.   ``AdminSite(name="...")``.
    
  1030. 
    
  1031. * The ``ModelAdmin.get_object()`` method (private API) now takes a third
    
  1032.   argument named ``from_field`` in order to specify which field should match
    
  1033.   the provided ``object_id``.
    
  1034. 
    
  1035. * The :meth:`ModelAdmin.response_delete()
    
  1036.   <django.contrib.admin.ModelAdmin.response_delete>` method
    
  1037.   now takes a second argument named ``obj_id`` which is the serialized
    
  1038.   identifier used to retrieve the object before deletion.
    
  1039. 
    
  1040. Default autoescaping of functions in ``django.template.defaultfilters``
    
  1041. -----------------------------------------------------------------------
    
  1042. 
    
  1043. In order to make built-in template filters that output HTML "safe by default"
    
  1044. when calling them in Python code, the following functions in
    
  1045. ``django.template.defaultfilters`` have been changed to automatically escape
    
  1046. their input value:
    
  1047. 
    
  1048. * ``join``
    
  1049. * ``linebreaksbr``
    
  1050. * ``linebreaks_filter``
    
  1051. * ``linenumbers``
    
  1052. * ``unordered_list``
    
  1053. * ``urlize``
    
  1054. * ``urlizetrunc``
    
  1055. 
    
  1056. You can revert to the old behavior by specifying ``autoescape=False`` if you
    
  1057. are passing trusted content. This change doesn't have any effect when using
    
  1058. the corresponding filters in templates.
    
  1059. 
    
  1060. Miscellaneous
    
  1061. -------------
    
  1062. 
    
  1063. * ``connections.queries`` is now a read-only attribute.
    
  1064. 
    
  1065. * Database connections are considered equal only if they're the same object.
    
  1066.   They aren't hashable any more.
    
  1067. 
    
  1068. * :class:`~django.middleware.gzip.GZipMiddleware` used to disable compression
    
  1069.   for some content types when the request is from Internet Explorer, in order
    
  1070.   to work around a bug in IE6 and earlier. This behavior could affect
    
  1071.   performance on IE7 and later. It was removed.
    
  1072. 
    
  1073. * ``URLField.to_python`` no longer adds a trailing slash to pathless URLs.
    
  1074. 
    
  1075. * The :tfilter:`length` template filter now returns ``0`` for an undefined
    
  1076.   variable, rather than an empty string.
    
  1077. 
    
  1078. * ``ForeignKey.default_error_message['invalid']`` has been changed from
    
  1079.   ``'%(model)s instance with pk %(pk)r does not exist.'`` to
    
  1080.   ``'%(model)s instance with %(field)s %(value)r does not exist.'`` If you are
    
  1081.   using this message in your own code, please update the list of interpolated
    
  1082.   parameters. Internally, Django will continue to provide the
    
  1083.   ``pk`` parameter in ``params`` for backwards compatibility.
    
  1084. 
    
  1085. * ``UserCreationForm.error_messages['duplicate_username']`` is no longer used.
    
  1086.   If you wish to customize that error message, :ref:`override it on the form
    
  1087.   <modelforms-overriding-default-fields>` using the ``'unique'`` key in
    
  1088.   ``Meta.error_messages['username']`` or, if you have a custom form field for
    
  1089.   ``'username'``, using the ``'unique'`` key in its
    
  1090.   :attr:`~django.forms.Field.error_messages` argument.
    
  1091. 
    
  1092. * The block ``usertools`` in the ``base.html`` template of
    
  1093.   :mod:`django.contrib.admin` now requires the ``has_permission`` context
    
  1094.   variable to be set. If you have any custom admin views that use this
    
  1095.   template, update them to pass :meth:`AdminSite.has_permission()
    
  1096.   <django.contrib.admin.AdminSite.has_permission>` as this new variable's
    
  1097.   value or simply include :meth:`AdminSite.each_context(request)
    
  1098.   <django.contrib.admin.AdminSite.each_context>` in the context.
    
  1099. 
    
  1100. * Internal changes were made to the :class:`~django.forms.ClearableFileInput`
    
  1101.   widget to allow more customization. The undocumented ``url_markup_template``
    
  1102.   attribute was removed in favor of ``template_with_initial``.
    
  1103. 
    
  1104. * For consistency with other major vendors, the ``en_GB`` locale now has Monday
    
  1105.   as the first day of the week.
    
  1106. 
    
  1107. * Seconds have been removed from any locales that had them in ``TIME_FORMAT``,
    
  1108.   ``DATETIME_FORMAT``, or ``SHORT_DATETIME_FORMAT``.
    
  1109. 
    
  1110. * The default max size of the Oracle test tablespace has increased from 300M
    
  1111.   (or 200M, before 1.7.2) to 500M.
    
  1112. 
    
  1113. * ``reverse()`` and ``reverse_lazy()`` now return Unicode strings instead of
    
  1114.   bytestrings.
    
  1115. 
    
  1116. * The ``CacheClass`` shim has been removed from all cache backends.
    
  1117.   These aliases were provided for backwards compatibility with Django 1.3.
    
  1118.   If you are still using them, please update your project to use the real
    
  1119.   class name found in the :setting:`BACKEND <CACHES-BACKEND>` key of the
    
  1120.   :setting:`CACHES` setting.
    
  1121. 
    
  1122. * By default, :func:`~django.core.management.call_command` now always skips the
    
  1123.   check framework (unless you pass it ``skip_checks=False``).
    
  1124. 
    
  1125. * When iterating over lines, :class:`~django.core.files.File` now uses
    
  1126.   :pep:`universal newlines <278>`. The following are recognized as ending a
    
  1127.   line: the Unix end-of-line convention ``'\n'``, the Windows convention
    
  1128.   ``'\r\n'``, and the old Macintosh convention ``'\r'``.
    
  1129. 
    
  1130. * The Memcached cache backends ``MemcachedCache`` and ``PyLibMCCache`` will
    
  1131.   delete a key if ``set()`` fails. This is necessary to ensure the ``cache_db``
    
  1132.   session store always fetches the most current session data.
    
  1133. 
    
  1134. * Private APIs ``override_template_loaders`` and ``override_with_test_loader``
    
  1135.   in ``django.test.utils`` were removed. Override ``TEMPLATES`` with
    
  1136.   ``override_settings`` instead.
    
  1137. 
    
  1138. * Warnings from the MySQL database backend are no longer converted to
    
  1139.   exceptions when :setting:`DEBUG` is ``True``.
    
  1140. 
    
  1141. * :class:`~django.http.HttpRequest` now has a simplified ``repr`` (e.g.
    
  1142.   ``<WSGIRequest: GET '/somepath/'>``). This won't change the behavior of
    
  1143.   the :class:`~django.views.debug.SafeExceptionReporterFilter` class.
    
  1144. 
    
  1145. * Class-based views that use :class:`~django.views.generic.edit.ModelFormMixin`
    
  1146.   will raise an :exc:`~django.core.exceptions.ImproperlyConfigured` exception
    
  1147.   when both the ``fields`` and ``form_class`` attributes are specified.
    
  1148.   Previously, ``fields`` was silently ignored.
    
  1149. 
    
  1150. * When following redirects, the test client now raises
    
  1151.   :exc:`~django.test.client.RedirectCycleError` if it detects a loop or hits a
    
  1152.   maximum redirect limit (rather than passing silently).
    
  1153. 
    
  1154. * Translatable strings set as the ``default`` parameter of the field are cast
    
  1155.   to concrete strings later, so the return type of ``Field.get_default()`` is
    
  1156.   different in some cases. There is no change to default values which are the
    
  1157.   result of a callable.
    
  1158. 
    
  1159. * ``GenericIPAddressField.empty_strings_allowed`` is now ``False``. Database
    
  1160.   backends that interpret empty strings as null (only Oracle among the backends
    
  1161.   that Django includes) will no longer convert null values back to an empty
    
  1162.   string. This is consistent with other backends.
    
  1163. 
    
  1164. * When the ``BaseCommand.leave_locale_alone``
    
  1165.   attribute is ``False``, translations are now deactivated instead of forcing
    
  1166.   the "en-us" locale. In the case your models contained non-English strings and
    
  1167.   you counted on English translations to be activated in management commands,
    
  1168.   this will not happen any longer. It might be that new database migrations are
    
  1169.   generated (once) after migrating to 1.8.
    
  1170. 
    
  1171. * :func:`django.utils.translation.get_language()` now returns ``None`` instead
    
  1172.   of :setting:`LANGUAGE_CODE` when translations are temporarily deactivated.
    
  1173. 
    
  1174. * When a translation doesn't exist for a specific literal, the fallback is now
    
  1175.   taken from the :setting:`LANGUAGE_CODE` language (instead of from the
    
  1176.   untranslated ``msgid`` message).
    
  1177. 
    
  1178. * The ``name`` field of :class:`django.contrib.contenttypes.models.ContentType`
    
  1179.   has been removed by a migration and replaced by a property. That means it's
    
  1180.   not possible to query or filter a ``ContentType`` by this field any longer.
    
  1181. 
    
  1182.   Be careful if you upgrade to Django 1.8 and skip Django 1.7. If you run
    
  1183.   ``manage.py migrate --fake``, this migration will be skipped and you'll see
    
  1184.   a ``RuntimeError: Error creating new content types.`` exception because the
    
  1185.   ``name`` column won't be dropped from the database. Use ``manage.py migrate
    
  1186.   --fake-initial`` to fake only the initial migration instead.
    
  1187. 
    
  1188. * The new :option:`migrate --fake-initial` option allows faking initial
    
  1189.   migrations. In 1.7, initial migrations were always automatically faked if all
    
  1190.   tables created in an initial migration already existed.
    
  1191. 
    
  1192. * An app *without* migrations with a ``ForeignKey`` to an app *with* migrations
    
  1193.   may now result in a foreign key constraint error when migrating the database
    
  1194.   or running tests. In Django 1.7, this could fail silently and result in a
    
  1195.   missing constraint. To resolve the error, add migrations to the app without
    
  1196.   them.
    
  1197. 
    
  1198. .. _deprecated-features-1.8:
    
  1199. 
    
  1200. Features deprecated in 1.8
    
  1201. ==========================
    
  1202. 
    
  1203. Selected methods in ``django.db.models.options.Options``
    
  1204. --------------------------------------------------------
    
  1205. 
    
  1206. As part of the formalization of the ``Model._meta`` API (from the
    
  1207. :class:`django.db.models.options.Options` class), a number of methods have been
    
  1208. deprecated and will be removed in Django 1.10:
    
  1209. 
    
  1210. * ``get_all_field_names()``
    
  1211. * ``get_all_related_objects()``
    
  1212. * ``get_all_related_objects_with_model()``
    
  1213. * ``get_all_related_many_to_many_objects()``
    
  1214. * ``get_all_related_m2m_objects_with_model()``
    
  1215. * ``get_concrete_fields_with_model()``
    
  1216. * ``get_field_by_name()``
    
  1217. * ``get_fields_with_model()``
    
  1218. * ``get_m2m_with_model()``
    
  1219. 
    
  1220. Loading ``cycle`` and ``firstof`` template tags from ``future`` library
    
  1221. -----------------------------------------------------------------------
    
  1222. 
    
  1223. Django 1.6 introduced ``{% load cycle from future %}`` and
    
  1224. ``{% load firstof from future %}`` syntax for forward compatibility of the
    
  1225. :ttag:`cycle` and :ttag:`firstof` template tags. This syntax is now deprecated
    
  1226. and will be removed in Django 1.10. You can simply remove the
    
  1227. ``{% load ... from future %}`` tags.
    
  1228. 
    
  1229. ``django.conf.urls.patterns()``
    
  1230. -------------------------------
    
  1231. 
    
  1232. In the olden days of Django, it was encouraged to reference views as strings
    
  1233. in ``urlpatterns``::
    
  1234. 
    
  1235.     urlpatterns = patterns('',
    
  1236.         url('^$', 'myapp.views.myview'),
    
  1237.     )
    
  1238. 
    
  1239. and Django would magically import ``myapp.views.myview`` internally and turn
    
  1240. the string into a real function reference. In order to reduce repetition when
    
  1241. referencing many views from the same module, the ``patterns()`` function takes
    
  1242. a required initial ``prefix`` argument which is prepended to all
    
  1243. views-as-strings in that set of ``urlpatterns``::
    
  1244. 
    
  1245.     urlpatterns = patterns('myapp.views',
    
  1246.         url('^$', 'myview'),
    
  1247.         url('^other/$', 'otherview'),
    
  1248.     )
    
  1249. 
    
  1250. In the modern era, we have updated the tutorial to instead recommend importing
    
  1251. your views module and referencing your view functions (or classes) directly.
    
  1252. This has a number of advantages, all deriving from the fact that we are using
    
  1253. normal Python in place of "Django String Magic": the errors when you mistype a
    
  1254. view name are less obscure, IDEs can help with autocompletion of view names,
    
  1255. etc.
    
  1256. 
    
  1257. So these days, the above use of the ``prefix`` arg is much more likely to be
    
  1258. written (and is better written) as::
    
  1259. 
    
  1260.     from myapp import views
    
  1261. 
    
  1262.     urlpatterns = patterns('',
    
  1263.         url('^$', views.myview),
    
  1264.         url('^other/$', views.otherview),
    
  1265.     )
    
  1266. 
    
  1267. Thus ``patterns()`` serves little purpose and is a burden when teaching new users
    
  1268. (answering the newbie's question "why do I need this empty string as the first
    
  1269. argument to ``patterns()``?"). For these reasons, we are deprecating it.
    
  1270. Updating your code is as simple as ensuring that ``urlpatterns`` is a list of
    
  1271. ``django.conf.urls.url()`` instances. For example::
    
  1272. 
    
  1273.     from django.conf.urls import url
    
  1274.     from myapp import views
    
  1275. 
    
  1276.     urlpatterns = [
    
  1277.         url('^$', views.myview),
    
  1278.         url('^other/$', views.otherview),
    
  1279.     ]
    
  1280. 
    
  1281. Passing a string as ``view`` to ``django.conf.urls.url()``
    
  1282. ----------------------------------------------------------
    
  1283. 
    
  1284. Related to the previous item, referencing views as strings in the ``url()``
    
  1285. function is deprecated. Pass the callable view as described in the previous
    
  1286. section instead.
    
  1287. 
    
  1288. Template-related settings
    
  1289. -------------------------
    
  1290. 
    
  1291. As a consequence of the multiple template engines refactor, several settings
    
  1292. are deprecated in favor of :setting:`TEMPLATES`:
    
  1293. 
    
  1294. * ``ALLOWED_INCLUDE_ROOTS``
    
  1295. * ``TEMPLATE_CONTEXT_PROCESSORS``
    
  1296. * ``TEMPLATE_DEBUG``
    
  1297. * ``TEMPLATE_DIRS``
    
  1298. * ``TEMPLATE_LOADERS``
    
  1299. * ``TEMPLATE_STRING_IF_INVALID``
    
  1300. 
    
  1301. ``django.core.context_processors``
    
  1302. ----------------------------------
    
  1303. 
    
  1304. Built-in template context processors have been moved to
    
  1305. ``django.template.context_processors``.
    
  1306. 
    
  1307. ``django.test.SimpleTestCase.urls``
    
  1308. -----------------------------------
    
  1309. 
    
  1310. The attribute ``SimpleTestCase.urls`` for specifying URLconf configuration in
    
  1311. tests has been deprecated and will be removed in Django 1.10. Use
    
  1312. :func:`@override_settings(ROOT_URLCONF=...) <django.test.override_settings>`
    
  1313. instead.
    
  1314. 
    
  1315. ``prefix`` argument to :func:`~django.conf.urls.i18n.i18n_patterns`
    
  1316. -------------------------------------------------------------------
    
  1317. 
    
  1318. Related to the previous item, the ``prefix`` argument to
    
  1319. :func:`django.conf.urls.i18n.i18n_patterns` has been deprecated. Simply pass a
    
  1320. list of ``django.conf.urls.url()`` instances instead.
    
  1321. 
    
  1322. Using an incorrect count of unpacked values in the :ttag:`for` template tag
    
  1323. ---------------------------------------------------------------------------
    
  1324. 
    
  1325. Using an incorrect count of unpacked values in :ttag:`for` tag will raise an
    
  1326. exception rather than fail silently in Django 1.10.
    
  1327. 
    
  1328. Passing a dotted path to ``reverse()`` and :ttag:`url`
    
  1329. ------------------------------------------------------
    
  1330. 
    
  1331. Reversing URLs by Python path is an expensive operation as it causes the
    
  1332. path being reversed to be imported. This behavior has also resulted in a
    
  1333. `security issue`_. Use :ref:`named URL patterns <naming-url-patterns>`
    
  1334. for reversing instead.
    
  1335. 
    
  1336. If you are using :mod:`django.contrib.sitemaps`, add the ``name`` argument to
    
  1337. the ``url`` that references :func:`django.contrib.sitemaps.views.sitemap`::
    
  1338. 
    
  1339.     from django.contrib.sitemaps.views import sitemap
    
  1340. 
    
  1341.     url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
    
  1342.         name='django.contrib.sitemaps.views.sitemap')
    
  1343. 
    
  1344. to ensure compatibility when reversing by Python path is removed in Django 1.10.
    
  1345. 
    
  1346. Similarly for GIS sitemaps, add ``name='django.contrib.gis.sitemaps.views.kml'``
    
  1347. or ``name='django.contrib.gis.sitemaps.views.kmz'``.
    
  1348. 
    
  1349. If you are using a Python path for the :setting:`LOGIN_URL` or
    
  1350. :setting:`LOGIN_REDIRECT_URL` setting, use the name of the ``url()`` instead.
    
  1351. 
    
  1352. .. _security issue: https://www.djangoproject.com/weblog/2014/apr/21/security/#s-issue-unexpected-code-execution-using-reverse
    
  1353. 
    
  1354. Aggregate methods and modules
    
  1355. -----------------------------
    
  1356. 
    
  1357. The ``django.db.models.sql.aggregates`` and
    
  1358. ``django.contrib.gis.db.models.sql.aggregates`` modules (both private API), have
    
  1359. been deprecated as ``django.db.models.aggregates`` and
    
  1360. ``django.contrib.gis.db.models.aggregates`` are now also responsible
    
  1361. for SQL generation. The old modules will be removed in Django 1.10.
    
  1362. 
    
  1363. If you were using the old modules, see :doc:`Query Expressions
    
  1364. </ref/models/expressions>` for instructions on rewriting custom aggregates
    
  1365. using the new stable API.
    
  1366. 
    
  1367. The following methods and properties of ``django.db.models.sql.query.Query``
    
  1368. have also been deprecated and the backwards compatibility shims will be removed
    
  1369. in Django 1.10:
    
  1370. 
    
  1371. * ``Query.aggregates``, replaced by ``annotations``.
    
  1372. * ``Query.aggregate_select``, replaced by ``annotation_select``.
    
  1373. * ``Query.add_aggregate()``, replaced by ``add_annotation()``.
    
  1374. * ``Query.set_aggregate_mask()``, replaced by ``set_annotation_mask()``.
    
  1375. * ``Query.append_aggregate_mask()``, replaced by ``append_annotation_mask()``.
    
  1376. 
    
  1377. Extending management command arguments through ``Command.option_list``
    
  1378. ----------------------------------------------------------------------
    
  1379. 
    
  1380. Management commands now use :py:mod:`argparse` instead of :py:mod:`optparse` to
    
  1381. parse command-line arguments passed to commands. This also means that the way
    
  1382. to add custom arguments to commands has changed: instead of extending the
    
  1383. ``option_list`` class list, you should now override the
    
  1384. :meth:`~django.core.management.BaseCommand.add_arguments` method and add
    
  1385. arguments through ``argparse.add_argument()``. See
    
  1386. :ref:`this example <custom-commands-options>` for more details.
    
  1387. 
    
  1388. ``django.core.management.NoArgsCommand``
    
  1389. ----------------------------------------
    
  1390. 
    
  1391. The class ``NoArgsCommand`` is now deprecated and will be removed in Django
    
  1392. 1.10. Use :class:`~django.core.management.BaseCommand` instead, which takes no
    
  1393. arguments by default.
    
  1394. 
    
  1395. Listing all migrations in a project
    
  1396. -----------------------------------
    
  1397. 
    
  1398. The ``--list`` option of the :djadmin:`migrate` management command is
    
  1399. deprecated and will be removed in Django 1.10. Use :djadmin:`showmigrations`
    
  1400. instead.
    
  1401. 
    
  1402. ``cache_choices`` option of ``ModelChoiceField`` and ``ModelMultipleChoiceField``
    
  1403. ---------------------------------------------------------------------------------
    
  1404. 
    
  1405. :class:`~django.forms.ModelChoiceField` and
    
  1406. :class:`~django.forms.ModelMultipleChoiceField` took an undocumented, untested
    
  1407. option ``cache_choices``. This cached querysets between multiple renderings of
    
  1408. the same ``Form`` object. This option is subject to an accelerated deprecation
    
  1409. and will be removed in Django 1.9.
    
  1410. 
    
  1411. ``django.template.resolve_variable()``
    
  1412. --------------------------------------
    
  1413. 
    
  1414. The function has been informally marked as "Deprecated" for some time. Replace
    
  1415. ``resolve_variable(path, context)`` with
    
  1416. ``django.template.Variable(path).resolve(context)``.
    
  1417. 
    
  1418. ``django.contrib.webdesign``
    
  1419. ----------------------------
    
  1420. 
    
  1421. It provided the :ttag:`lorem` template tag which is now included in the
    
  1422. built-in tags. Simply remove ``'django.contrib.webdesign'`` from
    
  1423. :setting:`INSTALLED_APPS` and ``{% load webdesign %}`` from your templates.
    
  1424. 
    
  1425. ``error_message`` argument to ``django.forms.RegexField``
    
  1426. ---------------------------------------------------------
    
  1427. 
    
  1428. It provided backwards compatibility for pre-1.0 code, but its functionality is
    
  1429. redundant. Use ``Field.error_messages['invalid']`` instead.
    
  1430. 
    
  1431. Old :tfilter:`unordered_list` syntax
    
  1432. ------------------------------------
    
  1433. 
    
  1434. An older (pre-1.0), more restrictive and verbose input format for the
    
  1435. :tfilter:`unordered_list` template filter has been deprecated::
    
  1436. 
    
  1437.     ['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]
    
  1438. 
    
  1439. Using the new syntax, this becomes::
    
  1440. 
    
  1441.     ['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]
    
  1442. 
    
  1443. ``django.forms.Field._has_changed()``
    
  1444. -------------------------------------
    
  1445. 
    
  1446. Rename this method to :meth:`~django.forms.Field.has_changed` by removing the
    
  1447. leading underscore. The old name will still work until Django 1.10.
    
  1448. 
    
  1449. ``django.utils.html.remove_tags()`` and ``removetags`` template filter
    
  1450. ----------------------------------------------------------------------
    
  1451. 
    
  1452. ``django.utils.html.remove_tags()`` as well as the template filter
    
  1453. ``removetags`` have been deprecated as they cannot guarantee safe output. Their
    
  1454. existence is likely to lead to their use in security-sensitive contexts where
    
  1455. they are not actually safe.
    
  1456. 
    
  1457. The unused and undocumented ``django.utils.html.strip_entities()`` function has
    
  1458. also been deprecated.
    
  1459. 
    
  1460. ``is_admin_site`` argument to ``django.contrib.auth.views.password_reset()``
    
  1461. ----------------------------------------------------------------------------
    
  1462. 
    
  1463. It's a legacy option that should no longer be necessary.
    
  1464. 
    
  1465. ``SubfieldBase``
    
  1466. ----------------
    
  1467. 
    
  1468. ``django.db.models.fields.subclassing.SubfieldBase`` has been deprecated and
    
  1469. will be removed in Django 1.10. Historically, it was used to handle fields where
    
  1470. type conversion was needed when loading from the database, but it was not used
    
  1471. in ``.values()`` calls or in aggregates. It has been replaced with
    
  1472. :meth:`~django.db.models.Field.from_db_value`.
    
  1473. 
    
  1474. The new approach doesn't call the :meth:`~django.db.models.Field.to_python`
    
  1475. method on assignment as was the case with ``SubfieldBase``. If you need that
    
  1476. behavior, reimplement the ``Creator`` class `from Django's source code
    
  1477. <https://github.com/django/django/blob/stable/1.8.x/django/db/models/fields/subclassing.py#L31-L44>`_
    
  1478. in your project.
    
  1479. 
    
  1480. ``django.utils.checksums``
    
  1481. --------------------------
    
  1482. 
    
  1483. The ``django.utils.checksums`` module has been deprecated and will be removed
    
  1484. in Django 1.10. The functionality it provided (validating checksum using the
    
  1485. Luhn algorithm) was undocumented and not used in Django. The module has been
    
  1486. moved to the `django-localflavor`_ package (version 1.1+).
    
  1487. 
    
  1488. .. _django-localflavor: https://pypi.org/project/django-localflavor/
    
  1489. 
    
  1490. ``InlineAdminForm.original_content_type_id``
    
  1491. --------------------------------------------
    
  1492. 
    
  1493. The ``original_content_type_id`` attribute on ``InlineAdminForm`` has been
    
  1494. deprecated and will be removed in Django 1.10. Historically, it was used
    
  1495. to construct the "view on site" URL. This URL is now accessible using the
    
  1496. ``absolute_url`` attribute of the form.
    
  1497. 
    
  1498. ``django.views.generic.edit.FormMixin.get_form()``’s ``form_class`` argument
    
  1499. ----------------------------------------------------------------------------
    
  1500. 
    
  1501. ``FormMixin`` subclasses that override the ``get_form()`` method should make
    
  1502. sure to provide a default value for the ``form_class`` argument since it's
    
  1503. now optional.
    
  1504. 
    
  1505. Rendering templates loaded by :func:`~django.template.loader.get_template()` with a :class:`~django.template.Context`
    
  1506. ---------------------------------------------------------------------------------------------------------------------
    
  1507. 
    
  1508. The return type of :func:`~django.template.loader.get_template()` has changed
    
  1509. in Django 1.8: instead of a :class:`django.template.Template`, it returns a
    
  1510. ``Template`` instance whose exact type depends on which backend loaded it.
    
  1511. 
    
  1512. Both classes provide a ``render()`` method, however, the former takes a
    
  1513. :class:`django.template.Context` as an argument while the latter expects a
    
  1514. :class:`dict`. This change is enforced through a deprecation path for Django
    
  1515. templates.
    
  1516. 
    
  1517. All this also applies to :func:`~django.template.loader.select_template()`.
    
  1518. 
    
  1519. :class:`~django.template.Template` and :class:`~django.template.Context` classes in template responses
    
  1520. ------------------------------------------------------------------------------------------------------
    
  1521. 
    
  1522. Some methods of :class:`~django.template.response.SimpleTemplateResponse` and
    
  1523. :class:`~django.template.response.TemplateResponse` accepted
    
  1524. :class:`django.template.Context` and :class:`django.template.Template` objects
    
  1525. as arguments. They should now receive :class:`dict` and backend-dependent
    
  1526. template objects respectively.
    
  1527. 
    
  1528. This also applies to the return types if you have subclassed either template
    
  1529. response class.
    
  1530. 
    
  1531. Check the :doc:`template response API documentation </ref/template-response>`
    
  1532. for details.
    
  1533. 
    
  1534. ``current_app`` argument of template-related APIs
    
  1535. -------------------------------------------------
    
  1536. 
    
  1537. The following functions and classes will no longer accept a ``current_app``
    
  1538. parameter to set an URL namespace in Django 1.10:
    
  1539. 
    
  1540. * ``django.shortcuts.render()``
    
  1541. * ``django.template.Context()``
    
  1542. * ``django.template.RequestContext()``
    
  1543. * ``django.template.response.TemplateResponse()``
    
  1544. 
    
  1545. Set ``request.current_app`` instead, where ``request`` is the first argument
    
  1546. to these functions or classes. If you're using a plain ``Context``, use a
    
  1547. ``RequestContext`` instead.
    
  1548. 
    
  1549. ``dictionary`` and ``context_instance`` arguments of rendering functions
    
  1550. ------------------------------------------------------------------------
    
  1551. 
    
  1552. The following functions will no longer accept the ``dictionary`` and
    
  1553. ``context_instance`` parameters in Django 1.10:
    
  1554. 
    
  1555. * ``django.shortcuts.render()``
    
  1556. * ``django.shortcuts.render_to_response()``
    
  1557. * ``django.template.loader.render_to_string()``
    
  1558. 
    
  1559. Use the ``context`` parameter instead. When ``dictionary`` is passed as a
    
  1560. positional argument, which is the most common idiom, no changes are needed.
    
  1561. 
    
  1562. If you're passing a :class:`~django.template.Context` in ``context_instance``,
    
  1563. pass a :class:`dict` in the ``context`` parameter instead. If you're passing a
    
  1564. :class:`~django.template.RequestContext`, pass the request separately in the
    
  1565. ``request`` parameter.
    
  1566. 
    
  1567. ``dirs`` argument of template-finding functions
    
  1568. -----------------------------------------------
    
  1569. 
    
  1570. The following functions will no longer accept a ``dirs`` parameter to override
    
  1571. ``TEMPLATE_DIRS`` in Django 1.10:
    
  1572. 
    
  1573. * :func:`django.template.loader.get_template()`
    
  1574. * :func:`django.template.loader.select_template()`
    
  1575. * :func:`django.shortcuts.render()`
    
  1576. * ``django.shortcuts.render_to_response()``
    
  1577. 
    
  1578. The parameter didn't work consistently across different template loaders and
    
  1579. didn't work for included templates.
    
  1580. 
    
  1581. ``django.template.loader.BaseLoader``
    
  1582. -------------------------------------
    
  1583. 
    
  1584. ``django.template.loader.BaseLoader`` was renamed to
    
  1585. ``django.template.loaders.base.Loader``. If you've written a custom template
    
  1586. loader that inherits ``BaseLoader``, you must inherit ``Loader`` instead.
    
  1587. 
    
  1588. ``django.test.utils.TestTemplateLoader``
    
  1589. ----------------------------------------
    
  1590. 
    
  1591. Private API ``django.test.utils.TestTemplateLoader`` is deprecated in favor of
    
  1592. ``django.template.loaders.locmem.Loader`` and will be removed in Django 1.9.
    
  1593. 
    
  1594. .. _storage-max-length-update:
    
  1595. 
    
  1596. Support for the ``max_length`` argument on custom ``Storage`` classes
    
  1597. ---------------------------------------------------------------------
    
  1598. 
    
  1599. ``Storage`` subclasses should add ``max_length=None`` as a parameter to
    
  1600. :meth:`~django.core.files.storage.Storage.get_available_name` and/or
    
  1601. :meth:`~django.core.files.storage.Storage.save` if they override either method.
    
  1602. Support for storages that do not accept this argument will be removed in
    
  1603. Django 1.10.
    
  1604. 
    
  1605. ``qn`` replaced by ``compiler``
    
  1606. -------------------------------
    
  1607. 
    
  1608. In previous Django versions, various internal ORM methods (mostly ``as_sql``
    
  1609. methods) accepted a ``qn`` (for "quote name") argument, which was a reference
    
  1610. to a function that quoted identifiers for sending to the database. In Django
    
  1611. 1.8, that argument has been renamed to ``compiler`` and is now a full
    
  1612. ``SQLCompiler`` instance. For backwards-compatibility, calling a
    
  1613. ``SQLCompiler`` instance performs the same name-quoting that the ``qn``
    
  1614. function used to. However, this backwards-compatibility shim is immediately
    
  1615. deprecated: you should rename your ``qn`` arguments to ``compiler``, and call
    
  1616. ``compiler.quote_name_unless_alias(...)`` where you previously called
    
  1617. ``qn(...)``.
    
  1618. 
    
  1619. Default value of ``RedirectView.permanent``
    
  1620. -------------------------------------------
    
  1621. 
    
  1622. The default value of the
    
  1623. :attr:`RedirectView.permanent <django.views.generic.base.RedirectView.permanent>`
    
  1624. attribute will change from ``True`` to ``False`` in Django 1.9.
    
  1625. 
    
  1626. Using ``AuthenticationMiddleware`` without ``SessionAuthenticationMiddleware``
    
  1627. ------------------------------------------------------------------------------
    
  1628. 
    
  1629. ``django.contrib.auth.middleware.SessionAuthenticationMiddleware`` was
    
  1630. added in Django 1.7. In Django 1.7.2, its functionality was moved to
    
  1631. ``auth.get_user()`` and, for backwards compatibility, enabled only if
    
  1632. ``'django.contrib.auth.middleware.SessionAuthenticationMiddleware'`` appears in
    
  1633. ``MIDDLEWARE_CLASSES``.
    
  1634. 
    
  1635. In Django 1.10, session verification will be enabled regardless of whether or not
    
  1636. ``SessionAuthenticationMiddleware`` is enabled (at which point
    
  1637. ``SessionAuthenticationMiddleware`` will have no significance). You can add it
    
  1638. to your ``MIDDLEWARE_CLASSES`` sometime before then to opt-in. Please read the
    
  1639. :ref:`upgrade considerations <session-invalidation-on-password-change>` first.
    
  1640. 
    
  1641. ``django.contrib.sitemaps.FlatPageSitemap``
    
  1642. -------------------------------------------
    
  1643. 
    
  1644. ``django.contrib.sitemaps.FlatPageSitemap`` has moved to
    
  1645. ``django.contrib.flatpages.sitemaps.FlatPageSitemap``. The old import location
    
  1646. is deprecated and will be removed in Django 1.9.
    
  1647. 
    
  1648. Model ``Field.related``
    
  1649. -----------------------
    
  1650. 
    
  1651. Private attribute ``django.db.models.Field.related`` is deprecated in favor
    
  1652. of ``Field.rel``.  The latter is an instance of
    
  1653. ``django.db.models.fields.related.ForeignObjectRel`` which replaces
    
  1654. ``django.db.models.related.RelatedObject``. The ``django.db.models.related``
    
  1655. module has been removed and the ``Field.related`` attribute will be removed in
    
  1656. Django 1.10.
    
  1657. 
    
  1658. ``ssi`` template tag
    
  1659. --------------------
    
  1660. 
    
  1661. The ``ssi`` template tag allows files to be included in a template by
    
  1662. absolute path. This is of limited use in most deployment situations, and
    
  1663. the :ttag:`include` tag often makes more sense. This tag is now deprecated and
    
  1664. will be removed in Django 1.10.
    
  1665. 
    
  1666. ``=`` as comparison operator in ``if`` template tag
    
  1667. ---------------------------------------------------
    
  1668. 
    
  1669. Using a single equals sign with the ``{% if %}`` template tag for equality
    
  1670. testing was undocumented and untested. It's now deprecated in favor of ``==``.
    
  1671. 
    
  1672. ``%(<foo>)s`` syntax in ``ModelFormMixin.success_url``
    
  1673. ------------------------------------------------------
    
  1674. 
    
  1675. The legacy ``%(<foo>)s`` syntax in :attr:`ModelFormMixin.success_url
    
  1676. <django.views.generic.edit.ModelFormMixin.success_url>` is deprecated and
    
  1677. will be removed in Django 1.10.
    
  1678. 
    
  1679. ``GeoQuerySet`` aggregate methods
    
  1680. ---------------------------------
    
  1681. 
    
  1682. The ``collect()``, ``extent()``, ``extent3d()``, ``make_line()``, and
    
  1683. ``unionagg()`` aggregate methods are deprecated and should be replaced by their
    
  1684. function-based aggregate equivalents (``Collect``, ``Extent``, ``Extent3D``,
    
  1685. ``MakeLine``, and ``Union``).
    
  1686. 
    
  1687. .. _deprecated-signature-of-allow-migrate:
    
  1688. 
    
  1689. Signature of the ``allow_migrate`` router method
    
  1690. ------------------------------------------------
    
  1691. 
    
  1692. The signature of the :meth:`allow_migrate` method of database routers has
    
  1693. changed from ``allow_migrate(db, model)`` to
    
  1694. ``allow_migrate(db, app_label, model_name=None, **hints)``.
    
  1695. 
    
  1696. When ``model_name`` is set, the value that was previously given through the
    
  1697. ``model`` positional argument may now be found inside the ``hints`` dictionary
    
  1698. under the key ``'model'``.
    
  1699. 
    
  1700. After switching to the new signature the router will also be called by the
    
  1701. :class:`~django.db.migrations.operations.RunPython` and
    
  1702. :class:`~django.db.migrations.operations.RunSQL` operations.
    
  1703. 
    
  1704. .. _removed-features-1.8:
    
  1705. 
    
  1706. Features removed in 1.8
    
  1707. =======================
    
  1708. 
    
  1709. These features have reached the end of their deprecation cycle and are removed
    
  1710. in Django 1.8. See :ref:`deprecated-features-1.6` for details, including how to
    
  1711. remove usage of these features.
    
  1712. 
    
  1713. * ``django.contrib.comments`` is removed.
    
  1714. 
    
  1715. * The following transaction management APIs are removed:
    
  1716. 
    
  1717.   - ``TransactionMiddleware``
    
  1718.   - the decorators and context managers ``autocommit``, ``commit_on_success``,
    
  1719.     and ``commit_manually``, defined in ``django.db.transaction``
    
  1720.   - the functions ``commit_unless_managed`` and ``rollback_unless_managed``,
    
  1721.     also defined in ``django.db.transaction``
    
  1722.   - the ``TRANSACTIONS_MANAGED`` setting
    
  1723. 
    
  1724. * The :ttag:`cycle` and :ttag:`firstof` template tags auto-escape their
    
  1725.   arguments.
    
  1726. 
    
  1727. * The ``SEND_BROKEN_LINK_EMAILS`` setting is removed.
    
  1728. 
    
  1729. * ``django.middleware.doc.XViewMiddleware`` is removed.
    
  1730. 
    
  1731. * The ``Model._meta.module_name`` alias is removed.
    
  1732. 
    
  1733. * The backward compatible shims introduced to rename ``get_query_set``
    
  1734.   and similar queryset methods are removed. This affects the following classes:
    
  1735.   ``BaseModelAdmin``, ``ChangeList``, ``BaseCommentNode``,
    
  1736.   ``GenericForeignKey``, ``Manager``, ``SingleRelatedObjectDescriptor`` and
    
  1737.   ``ReverseSingleRelatedObjectDescriptor``.
    
  1738. 
    
  1739. * The backward compatible shims introduced to rename the attributes
    
  1740.   ``ChangeList.root_query_set`` and ``ChangeList.query_set`` are removed.
    
  1741. 
    
  1742. * ``django.views.defaults.shortcut`` and ``django.conf.urls.shortcut`` are
    
  1743.   removed.
    
  1744. 
    
  1745. * Support for the Python Imaging Library (PIL) module is removed.
    
  1746. 
    
  1747. * The following private APIs are removed:
    
  1748. 
    
  1749.   - ``django.db.backend``
    
  1750.   - ``django.db.close_connection()``
    
  1751.   - ``django.db.backends.creation.BaseDatabaseCreation.set_autocommit()``
    
  1752.   - ``django.db.transaction.is_managed()``
    
  1753.   - ``django.db.transaction.managed()``
    
  1754. 
    
  1755. * ``django.forms.widgets.RadioInput`` is removed.
    
  1756. 
    
  1757. * The module ``django.test.simple`` and the class
    
  1758.   ``django.test.simple.DjangoTestSuiteRunner`` are removed.
    
  1759. 
    
  1760. * The module ``django.test._doctest`` is removed.
    
  1761. 
    
  1762. * The ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting is removed. This change
    
  1763.   affects both ``django.middleware.cache.CacheMiddleware`` and
    
  1764.   ``django.middleware.cache.UpdateCacheMiddleware`` despite the lack of a
    
  1765.   deprecation warning in the latter class.
    
  1766. 
    
  1767. * Usage of the hard-coded *Hold down "Control", or "Command" on a Mac, to select
    
  1768.   more than one.* string to override or append to user-provided ``help_text`` in
    
  1769.   forms for ``ManyToMany`` model fields is not performed by Django anymore
    
  1770.   either at the model or forms layer.
    
  1771. 
    
  1772. * The ``Model._meta.get_(add|change|delete)_permission`` methods are removed.
    
  1773. 
    
  1774. * The session key ``django_language`` is no longer read for backwards
    
  1775.   compatibility.
    
  1776. 
    
  1777. * Geographic Sitemaps are removed
    
  1778.   (``django.contrib.gis.sitemaps.views.index`` and
    
  1779.   ``django.contrib.gis.sitemaps.views.sitemap``).
    
  1780. 
    
  1781. * ``django.utils.html.fix_ampersands``, the ``fix_ampersands`` template filter,
    
  1782.   and ``django.utils.html.clean_html`` are removed.