1.8.txt 75 KB

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