1.8.txt 75 KB

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