1.8.txt 74 KB

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