1.8.txt 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758
  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 :ref:`"Long-Term Support"
  12. (LTS) <lts-releases>` release. It will receive security updates for at least
  13. three years after its release. Support for the previous LTS, Django 1.4, will
  14. end 6 months from the 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. * :djadmin:`inspectdb` now introspects database views on all database backends.
  322. In previous versions, only tables (not views) were inspected.
  323. * When calling management commands from code through :ref:`call_command
  324. <call-command>` and passing options, the option name can match the command
  325. line option name (without the initial dashes) or the final option destination
  326. variable name, but in either case, the resulting option received by the
  327. command is now always the ``dest`` name specified in the command option
  328. definition (as long as the command uses the new :py:mod:`argparse` module).
  329. * The :djadmin:`dbshell` command now supports MySQL's optional SSL certificate
  330. authority setting (``--ssl-ca``).
  331. * The :djadminopt:`--name` option for :djadmin:`makemigrations` allows you to
  332. to give the migration(s) a custom name instead of a generated one.
  333. * The :djadmin:`loaddata` command now prevents repeated fixture loading. If
  334. :setting:`FIXTURE_DIRS` contains duplicates or a default fixture directory
  335. path (``app_name/fixtures``), an exception is raised.
  336. * :djadmin:`makemigrations` now supports an :djadminopt:`--exit` option to
  337. exit with an error code if no migrations are created.
  338. * The new :djadmin:`showmigrations` command allows listing all migrations and
  339. their dependencies in a project.
  340. Middleware
  341. ^^^^^^^^^^
  342. * The :attr:`CommonMiddleware.response_redirect_class
  343. <django.middleware.common.CommonMiddleware.response_redirect_class>`
  344. attribute allows you to customize the redirects issued by the middleware.
  345. * A debug message will be logged to the ``django.request`` logger when a
  346. middleware raises a :exc:`~django.core.exceptions.MiddlewareNotUsed` exception
  347. in :setting:`DEBUG` mode.
  348. Migrations
  349. ^^^^^^^^^^
  350. * The :class:`~django.db.migrations.operations.RunSQL` operation can now handle
  351. parameters passed to the SQL statements.
  352. * It is now possible to have migrations (most probably :ref:`data migrations
  353. <data-migrations>`) for applications without models.
  354. * Migrations can now :ref:`serialize model managers
  355. <using-managers-in-migrations>` as part of the model state.
  356. * A :ref:`generic mechanism to handle the deprecation of model fields
  357. <migrations-removing-model-fields>` was added.
  358. * The :meth:`RunPython.noop() <django.db.migrations.operations.RunPython.noop>`
  359. and :attr:`RunSQL.noop <django.db.migrations.operations.RunSQL.noop>` class
  360. method/attribute were added to ease in making ``RunPython`` and ``RunSQL``
  361. operations reversible.
  362. * The migration operations :class:`~django.db.migrations.operations.RunPython`
  363. and :class:`~django.db.migrations.operations.RunSQL` now call the
  364. :meth:`allow_migrate` method of database routers. The router can use the
  365. newly introduced ``app_label`` and ``hints`` arguments to make a routing
  366. decision. To take advantage of this feature you need to update the router to
  367. the new ``allow_migrate`` signature, see the :ref:`deprecation section
  368. <deprecated-signature-of-allow-migrate>` for more details.
  369. Models
  370. ^^^^^^
  371. * Django now logs at most 9000 queries in ``connections.queries``, in order
  372. to prevent excessive memory usage in long-running processes in debug mode.
  373. * There is now a model ``Meta`` option to define a
  374. :attr:`default related name <django.db.models.Options.default_related_name>`
  375. for all relational fields of a model.
  376. * Pickling models and querysets across different versions of Django isn't
  377. officially supported (it may work, but there's no guarantee). An extra
  378. variable that specifies the current Django version is now added to the
  379. pickled state of models and querysets, and Django raises a ``RuntimeWarning``
  380. when these objects are unpickled in a different version than the one in
  381. which they were pickled.
  382. * Added :meth:`Model.from_db() <django.db.models.Model.from_db()>` which
  383. Django uses whenever objects are loaded using the ORM. The method allows
  384. customizing model loading behavior.
  385. * ``extra(select={...})`` now allows you to escape a literal ``%s`` sequence
  386. using ``%%s``.
  387. * :doc:`Custom Lookups</howto/custom-lookups>` can now be registered using
  388. a decorator pattern.
  389. * The new :attr:`Transform.bilateral <django.db.models.Transform.bilateral>`
  390. attribute allows creating bilateral transformations. These transformations
  391. are applied to both ``lhs`` and ``rhs`` when used in a lookup expression,
  392. providing opportunities for more sophisticated lookups.
  393. * SQL special characters (\, %, _) are now escaped properly when a pattern
  394. lookup (e.g. ``contains``, ``startswith``, etc.) is used with an ``F()``
  395. expression as the right-hand side. In those cases, the escaping is performed
  396. by the database, which can lead to somewhat complex queries involving nested
  397. ``REPLACE`` function calls.
  398. * You can now refresh model instances by using :meth:`Model.refresh_from_db()
  399. <django.db.models.Model.refresh_from_db>`.
  400. * You can now get the set of deferred fields for a model using
  401. :meth:`Model.get_deferred_fields() <django.db.models.Model.get_deferred_fields>`.
  402. * Model field ``default``’s are now used when primary key field's are set to
  403. ``None``.
  404. Signals
  405. ^^^^^^^
  406. * Exceptions from the ``(receiver, exception)`` tuples returned by
  407. :meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
  408. their traceback attached as a ``__traceback__`` attribute.
  409. * The ``environ`` argument, which contains the WSGI environment structure from
  410. the request, was added to the :data:`~django.core.signals.request_started`
  411. signal.
  412. * You can now import the :func:`~django.test.signals.setting_changed` signal
  413. from ``django.core.signals`` to avoid loading ``django.test`` in non-test
  414. situations. Django no longer does so itself.
  415. System Check Framework
  416. ^^^^^^^^^^^^^^^^^^^^^^
  417. * :attr:`~django.core.checks.register` can now be used as a function.
  418. Templates
  419. ^^^^^^^^^
  420. * :tfilter:`urlize` now supports domain-only links that include characters after
  421. the top-level domain (e.g. ``djangoproject.com/`` and
  422. ``djangoproject.com/download/``).
  423. * :tfilter:`urlize` doesn't treat exclamation marks at the end of a domain or
  424. its query string as part of the URL (the URL in e.g. ``'djangoproject.com!``
  425. is ``djangoproject.com``)
  426. * Added a :class:`locmem.Loader <django.template.loaders.locmem.Loader>`
  427. class that loads Django templates from a Python dictionary.
  428. * The :ttag:`now` tag can now store its output in a context variable with the
  429. usual syntax: ``{% now 'j n Y' as varname %}``.
  430. Requests and Responses
  431. ^^^^^^^^^^^^^^^^^^^^^^
  432. * ``WSGIRequest`` now respects paths starting with ``//``.
  433. * The :meth:`HttpRequest.build_absolute_uri()
  434. <django.http.HttpRequest.build_absolute_uri>` method now handles paths
  435. starting with ``//`` correctly.
  436. * If :setting:`DEBUG` is ``True`` and a request raises a
  437. :exc:`~django.core.exceptions.SuspiciousOperation`, the response will be
  438. rendered with a detailed error page.
  439. * The ``query_string`` argument of :class:`~django.http.QueryDict` is now
  440. optional, defaulting to ``None``, so a blank ``QueryDict`` can now be
  441. instantiated with ``QueryDict()`` instead of ``QueryDict(None)`` or
  442. ``QueryDict('')``.
  443. * The ``GET`` and ``POST`` attributes of an :class:`~django.http.HttpRequest`
  444. object are now :class:`~django.http.QueryDict`\s rather than dictionaries,
  445. and the ``FILES`` attribute is now a ``MultiValueDict``.
  446. This brings this class into line with the documentation and with
  447. ``WSGIRequest``.
  448. * The :attr:`HttpResponse.charset <django.http.HttpResponse.charset>` attribute
  449. was added.
  450. * ``WSGIRequestHandler`` now follows RFC in converting URI to IRI, using
  451. ``uri_to_iri()``.
  452. * The :meth:`HttpRequest.get_full_path()
  453. <django.http.HttpRequest.get_full_path>` method now escapes unsafe characters
  454. from the path portion of a Uniform Resource Identifier (URI) properly.
  455. * :class:`~django.http.HttpResponse` now implements a few additional methods
  456. like :meth:`~django.http.HttpResponse.getvalue` so that instances can be used
  457. as stream objects.
  458. * The new :meth:`HttpResponse.setdefault()
  459. <django.http.HttpResponse.setdefault>` method allows setting a header unless
  460. it has already been set.
  461. * You can use the new :class:`~django.http.FileResponse` to stream files.
  462. * The :func:`~django.views.decorators.http.condition` decorator for
  463. conditional view processing now supports the ``If-unmodified-since`` header.
  464. Tests
  465. ^^^^^
  466. * The :class:`RequestFactory.trace() <django.test.RequestFactory>`
  467. and :class:`Client.trace() <django.test.Client.trace>` methods were
  468. implemented, allowing you to create ``TRACE`` requests in your tests.
  469. * The ``count`` argument was added to
  470. :meth:`~django.test.SimpleTestCase.assertTemplateUsed`. This allows you to
  471. assert that a template was rendered a specific number of times.
  472. * The new :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` assertion
  473. allows you to test that two JSON fragments are not equal.
  474. * Added options to the :djadmin:`test` command to preserve the test database
  475. (:djadminopt:`--keepdb`), to run the test cases in reverse order
  476. (:djadminopt:`--reverse`), and to enable SQL logging for failing tests
  477. (:djadminopt:`--debug-sql`).
  478. * Added the :attr:`~django.test.Response.resolver_match` attribute to test
  479. client responses.
  480. * Added several settings that allow customization of test tablespace parameters
  481. for Oracle: :setting:`DATAFILE`, :setting:`DATAFILE_TMP`,
  482. :setting:`DATAFILE_MAXSIZE` and :setting:`DATAFILE_TMP_MAXSIZE`.
  483. * The :func:`~django.test.override_settings` decorator can now affect the
  484. master router in :setting:`DATABASE_ROUTERS`.
  485. * Added test client support for file uploads with file-like objects.
  486. * A shared cache is now used when testing with a SQLite in-memory database when
  487. using Python 3.4+ and SQLite 3.7.13+. This allows sharing the database
  488. between threads.
  489. Validators
  490. ^^^^^^^^^^
  491. * :class:`~django.core.validators.URLValidator` now supports IPv6 addresses,
  492. unicode domains, and URLs containing authentication data.
  493. Backwards incompatible changes in 1.8
  494. =====================================
  495. .. warning::
  496. In addition to the changes outlined in this section, be sure to review the
  497. :ref:`deprecation plan <deprecation-removed-in-1.8>` for any features that
  498. have been removed. If you haven't updated your code within the
  499. deprecation timeline for a given feature, its removal may appear as a
  500. backwards incompatible change.
  501. Related object operations are run in a transaction
  502. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  503. Some operations on related objects such as
  504. :meth:`~django.db.models.fields.related.RelatedManager.add()` or
  505. :ref:`direct assignment<direct-assignment>` ran multiple data modifying
  506. queries without wrapping them in transactions. To reduce the risk of data
  507. corruption, all data modifying methods that affect multiple related objects
  508. (i.e. ``add()``, ``remove()``, ``clear()``, and :ref:`direct assignment
  509. <direct-assignment>`) now perform their data modifying queries from within a
  510. transaction, provided your database supports transactions.
  511. This has one backwards incompatible side effect, signal handlers triggered from
  512. these methods are now executed within the method's transaction and any
  513. exception in a signal handler will prevent the whole operation.
  514. Assigning unsaved objects to relations raises an error
  515. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  516. Assigning unsaved objects to a :class:`~django.db.models.ForeignKey`,
  517. :class:`~django.contrib.contenttypes.fields.GenericForeignKey`, and
  518. :class:`~django.db.models.OneToOneField` now raises a :exc:`ValueError`.
  519. Previously, the assignment of an unsaved object would be silently ignored.
  520. For example::
  521. >>> book = Book.objects.create(name="Django")
  522. >>> book.author = Author(name="John")
  523. >>> book.author.save()
  524. >>> book.save()
  525. >>> Book.objects.get(name="Django")
  526. >>> book.author
  527. >>>
  528. Now, an error will be raised to prevent data loss::
  529. >>> book.author = Author(name="john")
  530. Traceback (most recent call last):
  531. ...
  532. ValueError: Cannot assign "<Author: John>": "Author" instance isn't saved in the database.
  533. If you require allowing the assignment of unsaved instances (the old behavior)
  534. and aren't concerned about the data loss possibility (e.g. you never save the
  535. objects to the database), you can disable this check by using the
  536. :attr:`~django.db.models.ForeignKey.allow_unsaved_instance_assignment`
  537. attribute.
  538. Management commands that only accept positional arguments
  539. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  540. If you have written a custom management command that only accepts positional
  541. arguments and you didn't specify the
  542. :attr:`~django.core.management.BaseCommand.args` command variable, you might
  543. get an error like ``Error: unrecognized arguments: ...``, as variable parsing
  544. is now based on :py:mod:`argparse` which doesn't implicitly accept positional
  545. arguments. You can make your command backwards compatible by simply setting the
  546. :attr:`~django.core.management.BaseCommand.args` class variable. However, if
  547. you don't have to keep compatibility with older Django versions, it's better to
  548. implement the new :meth:`~django.core.management.BaseCommand.add_arguments`
  549. method as described in :doc:`/howto/custom-management-commands`.
  550. Custom test management command arguments through test runner
  551. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  552. The method to add custom arguments to the `test` management command through the
  553. test runner has changed. Previously, you could provide an `option_list` class
  554. variable on the test runner to add more arguments (à la :py:mod:`optparse`).
  555. Now to implement the same behavior, you have to create an
  556. ``add_arguments(cls, parser)`` class method on the test runner and call
  557. ``parser.add_argument`` to add any custom arguments, as parser is now an
  558. :py:class:`argparse.ArgumentParser` instance.
  559. Model check ensures auto-generated column names are within limits specified by database
  560. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  561. A field name that's longer than the column name length supported by a database
  562. can create problems. For example, with MySQL you'll get an exception trying to
  563. create the column, and with PostgreSQL the column name is truncated by the
  564. database (you may see a warning in the PostgreSQL logs).
  565. A model check has been introduced to better alert users to this scenario before
  566. the actual creation of database tables.
  567. If you have an existing model where this check seems to be a false positive,
  568. for example on PostgreSQL where the name was already being truncated, simply
  569. use :attr:`~django.db.models.Field.db_column` to specify the name that's being
  570. used.
  571. The check also applies to the columns generated in an implicit
  572. ``ManyToManyField.through`` model. If you run into an issue there, use
  573. :attr:`~django.db.models.ManyToManyField.through` to create an explicit model
  574. and then specify :attr:`~django.db.models.Field.db_column` on its column(s)
  575. as needed.
  576. Query relation lookups now check object types
  577. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  578. Querying for model lookups now checks if the object passed is of correct type
  579. and raises a :exc:`ValueError` if not. Previously, Django didn't care if the
  580. object was of correct type; it just used the object's related field attribute
  581. (e.g. ``id``) for the lookup. Now, an error is raised to prevent incorrect
  582. lookups::
  583. >>> book = Book.objects.create(name="Django")
  584. >>> book = Book.objects.filter(author=book)
  585. Traceback (most recent call last):
  586. ...
  587. ValueError: Cannot query "<Book: Django>": Must be "Author" instance.
  588. ``select_related()`` now checks given fields
  589. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  590. ``select_related()`` now validates that the given fields actually exist.
  591. Previously, nonexistent fields were silently ignored. Now, an error is raised::
  592. >>> book = Book.objects.select_related('nonexistent_field')
  593. Traceback (most recent call last):
  594. ...
  595. FieldError: Invalid field name(s) given in select_related: 'nonexistent_field'
  596. The validation also makes sure that the given field is relational::
  597. >>> book = Book.objects.select_related('name')
  598. Traceback (most recent call last):
  599. ...
  600. FieldError: Non-relational field given in select_related: 'name'
  601. Default ``EmailField.max_length`` increased to 254
  602. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  603. The old default 75 character ``max_length`` was not capable of storing all
  604. possible RFC3696/5321-compliant email addresses. In order to store all
  605. possible valid email addresses, the ``max_length`` has been increased to 254
  606. characters. You will need to generate and apply database migrations for your
  607. affected models (or add ``max_length=75`` if you wish to keep the length on
  608. your current fields). A migration for
  609. :attr:`django.contrib.auth.models.User.email` is included.
  610. Support for PostgreSQL versions older than 9.0
  611. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  612. The end of upstream support periods was reached in July 2014 for PostgreSQL 8.4.
  613. As a consequence, Django 1.8 sets 9.0 as the minimum PostgreSQL version it
  614. officially supports.
  615. This also includes dropping support for PostGIS 1.3 and 1.4 as these versions
  616. are not supported on versions of PostgreSQL later than 8.4.
  617. Django also now requires the use of Psycopg2 version 2.4.5 or higher (or 2.5+
  618. if you want to use :mod:`django.contrib.postgres`).
  619. Support for MySQL versions older than 5.5
  620. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  621. The end of upstream support periods was reached in January 2012 for MySQL 5.0
  622. and December 2013 for MySQL 5.1. As a consequence, Django 1.8 sets 5.5 as the
  623. minimum MySQL version it officially supports.
  624. Support for Oracle versions older than 11.1
  625. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  626. The end of upstream support periods was reached in July 2010 for Oracle 9.2,
  627. January 2012 for Oracle 10.1, and July 2013 for Oracle 10.2. As a consequence,
  628. Django 1.8 sets 11.1 as the minimum Oracle version it officially supports.
  629. Specific privileges used instead of roles for tests on Oracle
  630. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  631. Earlier versions of Django granted the CONNECT and RESOURCE roles to the test
  632. user on Oracle. These roles have been deprecated, so Django 1.8 uses the
  633. specific underlying privileges instead. This changes the privileges required
  634. of the main user for running tests (unless the project is configured to avoid
  635. creating a test user). The exact privileges required now are detailed in
  636. :ref:`Oracle notes <oracle-notes>`.
  637. ``AbstractUser.last_login`` allows null values
  638. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  639. The :attr:`AbstractUser.last_login <django.contrib.auth.models.User.last_login>`
  640. field now allows null values. Previously, it defaulted to the time when the user
  641. was created which was misleading if the user never logged in. If you are using
  642. the default user (:class:`django.contrib.auth.models.User`), run the database
  643. migration included in ``contrib.auth``.
  644. If you are using a custom user model that inherits from ``AbstractUser``,
  645. you'll need to run :djadmin:`makemigrations` and generate a migration for your
  646. app that contains that model. Also, if wish to set ``last_login`` to ``NULL``
  647. for users who haven't logged in, you can run this query::
  648. from django.db import models
  649. from django.contrib.auth import get_user_model
  650. from django.contrib.auth.models import AbstractBaseUser
  651. UserModel = get_user_model()
  652. if issubclass(UserModel, AbstractBaseUser):
  653. UserModel._default_manager.filter(
  654. last_login=models.F('date_joined')
  655. ).update(last_login=None)
  656. :mod:`django.contrib.gis`
  657. ~~~~~~~~~~~~~~~~~~~~~~~~~
  658. * Support for GEOS 3.1 and GDAL 1.6 has been dropped.
  659. * Support for SpatiaLite < 2.4 has been dropped.
  660. * GIS-specific lookups have been refactored to use the
  661. :class:`django.db.models.Lookup` API.
  662. * The default ``str`` representation of
  663. :class:`~django.contrib.gis.geos.GEOSGeometry` objects has been changed from
  664. WKT to EWKT format (including the SRID). As this representation is used in
  665. the serialization framework, that means that ``dumpdata`` output will now
  666. contain the SRID value of geometry objects.
  667. Priority of context processors for ``TemplateResponse`` brought in line with ``render``
  668. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  669. The :class:`~django.template.response.TemplateResponse` constructor is designed to be a
  670. drop-in replacement for the :func:`~django.shortcuts.render` function. However,
  671. it had a slight incompatibility, in that for ``TemplateResponse``, context data
  672. from the passed in context dictionary could be shadowed by context data returned
  673. from context processors, whereas for ``render`` it was the other way
  674. around. This was a bug, and the behavior of ``render`` is more appropriate,
  675. since it allows the globally defined context processors to be overridden locally
  676. in the view. If you were relying on the fact context data in a
  677. ``TemplateResponse`` could be overridden using a context processor, you will
  678. need to change your code.
  679. Overriding ``setUpClass`` / ``tearDownClass`` in test cases
  680. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  681. The decorators :func:`~django.test.override_settings` and
  682. :func:`~django.test.modify_settings` now act at the class level when used as
  683. class decorators. As a consequence, when overriding ``setUpClass()`` or
  684. ``tearDownClass()``, the ``super`` implementation should always be called.
  685. Removal of ``django.contrib.formtools``
  686. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  687. The formtools contrib app has been moved to a separate package and the
  688. relevant documentation pages have been updated or removed.
  689. The new package is available `on Github`_ and on PyPI.
  690. .. _on GitHub: https://github.com/django/django-formtools/
  691. Database connection reloading between tests
  692. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  693. Django previously closed database connections between each test within a
  694. ``TestCase``. This is no longer the case as Django now wraps the whole
  695. ``TestCase`` within a transaction. If some of your tests relied on the old
  696. behavior, you should have them inherit from ``TransactionTestCase`` instead.
  697. Cleanup of the ``django.template`` namespace
  698. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  699. If you've been relying on private APIs exposed in the ``django.template``
  700. module, you may have to import them from ``django.template.base`` instead.
  701. Also private APIs ``django.template.base.compile_string()``,
  702. ``django.template.loader.find_template()``, and
  703. ``django.template.loader.get_template_from_string()`` were removed.
  704. ``model`` attribute on private model relations
  705. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  706. In earlier versions of Django, on a model with a reverse foreign key
  707. relationship (for example), ``model._meta.get_all_related_objects()`` returned
  708. the relationship as a ``django.db.models.related.RelatedObject`` with the
  709. ``model`` attribute set to the source of the relationship. Now, this method
  710. returns the relationship as ``django.db.models.fields.related.ManyToOneRel``
  711. (private API ``RelatedObject`` has been removed), and the ``model`` attribute
  712. is set to the target of the relationship instead of the source. The source
  713. model is accessible on the ``related_model`` attribute instead.
  714. Consider this example from the tutorial in Django 1.8::
  715. >>> p = Poll.objects.get(pk=1)
  716. >>> p._meta.get_all_related_objects()
  717. [<ManyToOneRel: polls.choice>]
  718. >>> p._meta.get_all_related_objects()[0].model
  719. <class 'polls.models.Poll'>
  720. >>> p._meta.get_all_related_objects()[0].related_model
  721. <class 'polls.models.Choice'>
  722. and compare it to the behavior on older versions::
  723. >>> p._meta.get_all_related_objects()
  724. [<RelatedObject: polls:choice related to poll>]
  725. >>> p._meta.get_all_related_objects()[0].model
  726. <class 'polls.models.Choice'>
  727. To access the source model, you can use a pattern like this to write code that
  728. will work with both Django 1.8 and older versions::
  729. for relation in opts.get_all_related_objects():
  730. to_model = getattr(relation, 'related_model', relation.model)
  731. Also note that ``get_all_related_objects()`` is deprecated in 1.8. See the
  732. :ref:`upgrade guide <migrating-old-meta-api>` for the new API.
  733. Database backend API
  734. ~~~~~~~~~~~~~~~~~~~~
  735. The following changes to the database backend API are documented to assist
  736. those writing third-party backends in updating their code:
  737. * ``BaseDatabaseXXX`` classes have been moved to ``django.db.backends.base``.
  738. Please import them from the new locations::
  739. from django.db.backends.base.base import BaseDatabaseWrapper
  740. from django.db.backends.base.client import BaseDatabaseClient
  741. from django.db.backends.base.creation import BaseDatabaseCreation
  742. from django.db.backends.base.features import BaseDatabaseFeatures
  743. from django.db.backends.base.introspection import BaseDatabaseIntrospection
  744. from django.db.backends.base.introspection import FieldInfo, TableInfo
  745. from django.db.backends.base.operations import BaseDatabaseOperations
  746. from django.db.backends.base.schema import BaseDatabaseSchemaEditor
  747. from django.db.backends.base.validation import BaseDatabaseValidation
  748. * The ``data_types``, ``data_types_suffix``, and
  749. ``data_type_check_constraints`` attributes have moved from the
  750. ``DatabaseCreation`` class to ``DatabaseWrapper``.
  751. * The ``SQLCompiler.as_sql()`` method now takes a ``subquery`` parameter
  752. (:ticket:`24164`).
  753. * The ``BaseDatabaseOperations.date_interval_sql()`` method now only takes a
  754. ``timedelta`` parameter.
  755. :mod:`django.contrib.admin`
  756. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  757. * ``AdminSite`` no longer takes an ``app_name`` argument and its ``app_name``
  758. attribute has been removed. The application name is always ``admin`` (as
  759. opposed to the instance name which you can still customize using
  760. ``AdminSite(name="...")``.
  761. * The ``ModelAdmin.get_object()`` method (private API) now takes a third
  762. argument named ``from_field`` in order to specify which field should match
  763. the provided ``object_id``.
  764. * The :meth:`ModelAdmin.response_delete()
  765. <django.contrib.admin.ModelAdmin.response_delete>` method
  766. now takes a second argument named ``obj_id`` which is the serialized
  767. identifier used to retrieve the object before deletion.
  768. Default autoescaping of functions in ``django.template.defaultfilters``
  769. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  770. In order to make built-in template filters that output HTML "safe by default"
  771. when calling them in Python code, the following functions in
  772. ``django.template.defaultfilters`` have been changed to automatically escape
  773. their input value:
  774. * ``join``
  775. * ``linebreaksbr``
  776. * ``linebreaks_filter``
  777. * ``linenumbers``
  778. * ``unordered_list``
  779. * ``urlize``
  780. * ``urlizetrunc``
  781. You can revert to the old behavior by specifying ``autoescape=False`` if you
  782. are passing trusted content. This change doesn't have any effect when using
  783. the corresponding filters in templates.
  784. Miscellaneous
  785. ~~~~~~~~~~~~~
  786. * ``connections.queries`` is now a read-only attribute.
  787. * Database connections are considered equal only if they're the same object.
  788. They aren't hashable any more.
  789. * :class:`~django.middleware.gzip.GZipMiddleware` used to disable compression
  790. for some content types when the request is from Internet Explorer, in order
  791. to work around a bug in IE6 and earlier. This behavior could affect
  792. performance on IE7 and later. It was removed.
  793. * ``URLField.to_python`` no longer adds a trailing slash to pathless URLs.
  794. * The :tfilter:`length` template filter now returns ``0`` for an undefined
  795. variable, rather than an empty string.
  796. * ``ForeignKey.default_error_message['invalid']`` has been changed from
  797. ``'%(model)s instance with pk %(pk)r does not exist.'`` to
  798. ``'%(model)s instance with %(field)s %(value)r does not exist.'`` If you are
  799. using this message in your own code, please update the list of interpolated
  800. parameters. Internally, Django will continue to provide the
  801. ``pk`` parameter in ``params`` for backwards compatibility.
  802. * ``UserCreationForm.errors_messages['duplicate_username']`` is no longer used.
  803. If you wish to customize that error message, :ref:`override it on the form
  804. <modelforms-overriding-default-fields>` using the ``'unique'`` key in
  805. ``Meta.errors_messages['username']`` or, if you have a custom form field for
  806. ``'username'``, using the the ``'unique'`` key in its
  807. :attr:`~django.forms.Field.error_messages` argument.
  808. * The block ``usertools`` in the ``base.html`` template of
  809. :mod:`django.contrib.admin` now requires the ``has_permission`` context
  810. variable to be set. If you have any custom admin views that use this
  811. template, update them to pass :meth:`AdminSite.has_permission()
  812. <django.contrib.admin.AdminSite.has_permission>` as this new variable's
  813. value or simply include :meth:`AdminSite.each_context(request)
  814. <django.contrib.admin.AdminSite.each_context>` in the context.
  815. * Internal changes were made to the :class:`~django.forms.ClearableFileInput`
  816. widget to allow more customization. The undocumented ``url_markup_template``
  817. attribute was removed in favor of ``template_with_initial``.
  818. * For consistency with other major vendors, the ``en_GB`` locale now has Monday
  819. as the first day of the week.
  820. * Seconds have been removed from any locales that had them in ``TIME_FORMAT``,
  821. ``DATETIME_FORMAT``, or ``SHORT_DATETIME_FORMAT``.
  822. * The default max size of the Oracle test tablespace has increased from 300M
  823. (or 200M, before 1.7.2) to 500M.
  824. * :func:`~django.core.urlresolvers.reverse` and
  825. :func:`~django.core.urlresolvers.reverse_lazy` now return Unicode strings
  826. instead of byte strings.
  827. * The ``CacheClass`` shim has been removed from all cache backends.
  828. These aliases were provided for backwards compatibility with Django 1.3.
  829. If you are still using them, please update your project to use the real
  830. class name found in the :setting:`BACKEND <CACHES-BACKEND>` key of the
  831. :setting:`CACHES` setting.
  832. * By default, :ref:`call_command <call-command>` now always skips the check
  833. framework (unless you pass it ``skip_checks=False``).
  834. * When iterating over lines, :class:`~django.core.files.File` now uses
  835. `universal newlines`_. The following are recognized as ending a line: the
  836. Unix end-of-line convention ``'\n'``, the Windows convention ``'\r\n'``, and
  837. the old Macintosh convention ``'\r'``.
  838. .. _universal newlines: https://www.python.org/dev/peps/pep-0278
  839. * The Memcached cache backends ``MemcachedCache`` and ``PyLibMCCache`` will
  840. delete a key if ``set()`` fails. This is necessary to ensure the ``cache_db``
  841. session store always fetches the most current session data.
  842. * Private APIs ``override_template_loaders`` and ``override_with_test_loader``
  843. in ``django.test.utils`` were removed. Override ``TEMPLATES`` with
  844. ``override_settings`` instead.
  845. * Warnings from the MySQL database backend are no longer converted to
  846. exceptions when :setting:`DEBUG` is ``True``.
  847. * :class:`~django.http.HttpRequest` now has a simplified ``repr`` (e.g.
  848. ``<WSGIRequest: GET '/somepath/'>``). This won't change the behavior of
  849. the :class:`~django.views.debug.SafeExceptionReporterFilter` class.
  850. * Class-based views that use :class:`~django.views.generic.edit.ModelFormMixin`
  851. will raise an :exc:`~django.core.exceptions.ImproperlyConfigured` exception
  852. when both the ``fields`` and ``form_class`` attributes are specified.
  853. Previously, ``fields`` was silently ignored.
  854. * When following redirects, the test client now raises
  855. :exc:`~django.test.client.RedirectCycleError` if it detects a loop or hits a
  856. maximum redirect limit (rather than passing silently).
  857. * Translatable strings set as the ``default`` parameter of the field are cast
  858. to concrete strings later, so the return type of ``Field.get_default()`` is
  859. different in some cases. There is no change to default values which are the
  860. result of a callable.
  861. * ``GenericIPAddressField.empty_strings_allowed`` is now ``False``. Database
  862. backends that interpret empty strings as null (only Oracle among the backends
  863. that Django includes) will no longer convert null values back to an empty
  864. string. This is consistent with other backends.
  865. * When the :attr:`~django.core.management.BaseCommand.leave_locale_alone`
  866. attribute is ``False``, translations are now deactivated instead of forcing
  867. the "en-us" locale. In the case your models contained non-English strings and
  868. you counted on English translations to be activated in management commands,
  869. this will not happen any longer. It might be that new database migrations are
  870. generated (once) after migrating to 1.8.
  871. * :func:`django.utils.translation.get_language()` now returns ``None`` instead
  872. of :setting:`LANGUAGE_CODE` when translations are temporarily deactivated.
  873. * When a translation doesn't exist for a specific literal, the fallback is now
  874. taken from the :setting:`LANGUAGE_CODE` language (instead of from the
  875. untranslated ``msgid`` message).
  876. * The ``name`` field of :class:`django.contrib.contenttypes.models.ContentType`
  877. has been removed by a migration and replaced by a property. That means it's
  878. not possible to query or filter a ``ContentType`` by this field any longer.
  879. * :djadmin:`migrate` now accepts the :djadminopt:`--fake-initial` option to
  880. allow faking initial migrations. In 1.7 initial migrations were always
  881. automatically faked if all tables created in an initial migration already
  882. existed.
  883. .. _deprecated-features-1.8:
  884. Features deprecated in 1.8
  885. ==========================
  886. Selected methods in ``django.db.models.options.Options``
  887. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  888. As part of the formalization of the ``Model._meta`` API (from the
  889. :class:`django.db.models.options.Options` class), a number of methods have been
  890. deprecated and will be removed in Django 1.10:
  891. * ``get_all_field_names()``
  892. * ``get_all_related_objects()``
  893. * ``get_all_related_objects_with_model()``
  894. * ``get_all_related_many_to_many_objects()``
  895. * ``get_all_related_m2m_objects_with_model()``
  896. * ``get_concrete_fields_with_model()``
  897. * ``get_field_by_name()``
  898. * ``get_fields_with_model()``
  899. * ``get_m2m_with_model()``
  900. A :ref:`migration guide <migrating-old-meta-api>` has been provided to assist
  901. in converting your code from the old API to the new, official API.
  902. Loading ``cycle`` and ``firstof`` template tags from ``future`` library
  903. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  904. Django 1.6 introduced ``{% load cycle from future %}`` and
  905. ``{% load firstof from future %}`` syntax for forward compatibility of the
  906. :ttag:`cycle` and :ttag:`firstof` template tags. This syntax is now deprecated
  907. and will be removed in Django 1.10. You can simply remove the
  908. ``{% load ... from future %}`` tags.
  909. ``django.conf.urls.patterns()``
  910. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  911. In the olden days of Django, it was encouraged to reference views as strings
  912. in ``urlpatterns``::
  913. urlpatterns = patterns('',
  914. url('^$', 'myapp.views.myview'),
  915. )
  916. and Django would magically import ``myapp.views.myview`` internally and turn
  917. the string into a real function reference. In order to reduce repetition when
  918. referencing many views from the same module, the ``patterns()`` function takes
  919. a required initial ``prefix`` argument which is prepended to all
  920. views-as-strings in that set of ``urlpatterns``::
  921. urlpatterns = patterns('myapp.views',
  922. url('^$', 'myview'),
  923. url('^other/$', 'otherview'),
  924. )
  925. In the modern era, we have updated the tutorial to instead recommend importing
  926. your views module and referencing your view functions (or classes) directly.
  927. This has a number of advantages, all deriving from the fact that we are using
  928. normal Python in place of "Django String Magic": the errors when you mistype a
  929. view name are less obscure, IDEs can help with autocompletion of view names,
  930. etc.
  931. So these days, the above use of the ``prefix`` arg is much more likely to be
  932. written (and is better written) as::
  933. from myapp import views
  934. urlpatterns = patterns('',
  935. url('^$', views.myview),
  936. url('^other/$', views.otherview),
  937. )
  938. Thus ``patterns()`` serves little purpose and is a burden when teaching new users
  939. (answering the newbie's question "why do I need this empty string as the first
  940. argument to ``patterns()``?"). For these reasons, we are deprecating it.
  941. Updating your code is as simple as ensuring that ``urlpatterns`` is a list of
  942. :func:`django.conf.urls.url` instances. For example::
  943. from django.conf.urls import url
  944. from myapp import views
  945. urlpatterns = [
  946. url('^$', views.myview),
  947. url('^other/$', views.otherview),
  948. ]
  949. Passing a string as ``view`` to :func:`~django.conf.urls.url`
  950. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  951. Related to the previous item, referencing views as strings in the ``url()``
  952. function is deprecated. Pass the callable view as described in the previous
  953. section instead.
  954. Template-related settings
  955. ~~~~~~~~~~~~~~~~~~~~~~~~~
  956. As a consequence of the multiple template engines refactor, several settings
  957. are deprecated in favor of :setting:`TEMPLATES`:
  958. * ``ALLOWED_INCLUDE_ROOTS``
  959. * ``TEMPLATE_CONTEXT_PROCESSORS``
  960. * ``TEMPLATE_DEBUG``
  961. * ``TEMPLATE_DIRS``
  962. * ``TEMPLATE_LOADERS``
  963. * ``TEMPLATE_STRING_IF_INVALID``
  964. ``django.core.context_processors``
  965. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  966. Built-in template context processors have been moved to
  967. ``django.template.context_processors``.
  968. ``django.test.SimpleTestCase.urls``
  969. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  970. The attribute :attr:`SimpleTestCase.urls <django.test.SimpleTestCase.urls>`
  971. for specifying URLconf configuration in tests has been deprecated and will be
  972. removed in Django 1.10. Use :func:`@override_settings(ROOT_URLCONF=...)
  973. <django.test.override_settings>` instead.
  974. ``prefix`` argument to :func:`~django.conf.urls.i18n.i18n_patterns`
  975. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  976. Related to the previous item, the ``prefix`` argument to
  977. :func:`django.conf.urls.i18n.i18n_patterns` has been deprecated. Simply pass a
  978. list of :func:`django.conf.urls.url` instances instead.
  979. Using an incorrect count of unpacked values in the :ttag:`for` template tag
  980. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  981. Using an incorrect count of unpacked values in :ttag:`for` tag will raise an
  982. exception rather than fail silently in Django 1.10.
  983. Passing a dotted path to :func:`~django.core.urlresolvers.reverse()` and :ttag:`url`
  984. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  985. Reversing URLs by Python path is an expensive operation as it causes the
  986. path being reversed to be imported. This behavior has also resulted in a
  987. `security issue`_. Use :ref:`named URL patterns <naming-url-patterns>`
  988. for reversing instead.
  989. If you are using :mod:`django.contrib.sitemaps`, add the ``name`` argument to
  990. the ``url`` that references :func:`django.contrib.sitemaps.views.sitemap`::
  991. from django.contrib.sitemaps.views import sitemap
  992. url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
  993. name='django.contrib.sitemaps.views.sitemap')
  994. to ensure compatibility when reversing by Python path is removed in Django 1.10.
  995. Similarly for GIS sitemaps, add ``name='django.contrib.gis.sitemaps.views.kml'``
  996. or ``name='django.contrib.gis.sitemaps.views.kmz'``.
  997. .. _security issue: https://www.djangoproject.com/weblog/2014/apr/21/security/#s-issue-unexpected-code-execution-using-reverse
  998. Aggregate methods and modules
  999. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1000. The ``django.db.models.sql.aggregates`` and
  1001. ``django.contrib.gis.db.models.sql.aggregates`` modules (both private API), have
  1002. been deprecated as ``django.db.models.aggregates`` and
  1003. ``django.contrib.gis.db.models.aggregates`` are now also responsible
  1004. for SQL generation. The old modules will be removed in Django 1.10.
  1005. If you were using the old modules, see :doc:`Query Expressions
  1006. </ref/models/expressions>` for instructions on rewriting custom aggregates
  1007. using the new stable API.
  1008. The following methods and properties of ``django.db.models.sql.query.Query``
  1009. have also been deprecated and the backwards compatibility shims will be removed
  1010. in Django 1.10:
  1011. * ``Query.aggregates``, replaced by ``annotations``.
  1012. * ``Query.aggregate_select``, replaced by ``annotation_select``.
  1013. * ``Query.add_aggregate()``, replaced by ``add_annotation()``.
  1014. * ``Query.set_aggregate_mask()``, replaced by ``set_annotation_mask()``.
  1015. * ``Query.append_aggregate_mask()``, replaced by ``append_annotation_mask()``.
  1016. Extending management command arguments through ``Command.option_list``
  1017. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1018. Management commands now use :py:mod:`argparse` instead of :py:mod:`optparse` to
  1019. parse command-line arguments passed to commands. This also means that the way
  1020. to add custom arguments to commands has changed: instead of extending the
  1021. ``option_list`` class list, you should now override the
  1022. :meth:`~django.core.management.BaseCommand.add_arguments` method and add
  1023. arguments through ``argparse.add_argument()``. See
  1024. :ref:`this example <custom-commands-options>` for more details.
  1025. ``django.core.management.NoArgsCommand``
  1026. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1027. The class :class:`~django.core.management.NoArgsCommand` is now deprecated and
  1028. will be removed in Django 1.10. Use :class:`~django.core.management.BaseCommand`
  1029. instead, which takes no arguments by default.
  1030. Listing all migrations in a project
  1031. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1032. The ``--list`` option of the :djadmin:`migrate` management command is
  1033. deprecated and will be removed in Django 1.10. Use :djadmin:`showmigrations`
  1034. instead.
  1035. ``cache_choices`` option of ``ModelChoiceField`` and ``ModelMultipleChoiceField``
  1036. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1037. :class:`~django.forms.ModelChoiceField` and
  1038. :class:`~django.forms.ModelMultipleChoiceField` took an undocumented, untested
  1039. option ``cache_choices``. This cached querysets between multiple renderings of
  1040. the same ``Form`` object. This option is subject to an accelerated deprecation
  1041. and will be removed in Django 1.9.
  1042. ``django.template.resolve_variable()``
  1043. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1044. The function has been informally marked as "Deprecated" for some time. Replace
  1045. ``resolve_variable(path, context)`` with
  1046. ``django.template.Variable(path).resolve(context)``.
  1047. ``django.contrib.webdesign``
  1048. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1049. It provided the :ttag:`lorem` template tag which is now included in the
  1050. built-in tags. Simply remove ``'django.contrib.webdesign'`` from
  1051. :setting:`INSTALLED_APPS` and ``{% load webdesign %}`` from your templates.
  1052. ``error_message`` argument to ``django.forms.RegexField``
  1053. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1054. It provided backwards compatibility for pre-1.0 code, but its functionality is
  1055. redundant. Use ``Field.error_messages['invalid']`` instead.
  1056. Old :tfilter:`unordered_list` syntax
  1057. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1058. An older (pre-1.0), more restrictive and verbose input format for the
  1059. :tfilter:`unordered_list` template filter has been deprecated::
  1060. ``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``
  1061. Using the new syntax, this becomes::
  1062. ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``
  1063. ``django.forms.Field._has_changed()``
  1064. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1065. Rename this method to :meth:`~django.forms.Field.has_changed` by removing the
  1066. leading underscore. The old name will still work until Django 1.10.
  1067. ``django.utils.html.remove_tags()`` and ``removetags`` template filter
  1068. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1069. ``django.utils.html.remove_tags()`` as well as the template filter
  1070. ``removetags`` have been deprecated as they cannot guarantee safe output. Their
  1071. existence is likely to lead to their use in security-sensitive contexts where
  1072. they are not actually safe.
  1073. The unused and undocumented ``django.utils.html.strip_entities()`` function has
  1074. also been deprecated.
  1075. ``is_admin_site`` argument to ``django.contrib.auth.views.password_reset()``
  1076. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1077. It's a legacy option that should no longer be necessary.
  1078. ``SubfieldBase``
  1079. ~~~~~~~~~~~~~~~~
  1080. ``django.db.models.fields.subclassing.SubfieldBase`` has been deprecated and
  1081. will be removed in Django 1.10. Historically, it was used to handle fields where
  1082. type conversion was needed when loading from the database, but it was not used
  1083. in ``.values()`` calls or in aggregates. It has been replaced with
  1084. :meth:`~django.db.models.Field.from_db_value`. Note that the new approach does
  1085. not call the :meth:`~django.db.models.Field.to_python` method on assignment
  1086. as was the case with ``SubfieldBase``.
  1087. ``django.utils.checksums``
  1088. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1089. The ``django.utils.checksums`` module has been deprecated and will be removed
  1090. in Django 1.10. The functionality it provided (validating checksum using the
  1091. Luhn algorithm) was undocumented and not used in Django. The module has been
  1092. moved to the `django-localflavor`_ package (version 1.1+).
  1093. .. _django-localflavor: https://pypi.python.org/pypi/django-localflavor
  1094. ``InlineAdminForm.original_content_type_id``
  1095. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1096. The ``original_content_type_id`` attribute on ``InlineAdminForm`` has been
  1097. deprecated and will be removed in Django 1.10. Historically, it was used
  1098. to construct the "view on site" URL. This URL is now accessible using the
  1099. ``absolute_url`` attribute of the form.
  1100. ``django.views.generic.edit.FormMixin.get_form()``’s ``form_class`` argument
  1101. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1102. ``FormMixin`` subclasses that override the ``get_form()`` method should make
  1103. sure to provide a default value for the ``form_class`` argument since it's
  1104. now optional.
  1105. Rendering templates loaded by :func:`~django.template.loader.get_template()` with a :class:`~django.template.Context`
  1106. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1107. The return type of :func:`~django.template.loader.get_template()` has changed
  1108. in Django 1.8: instead of a :class:`django.template.Template`, it returns a
  1109. ``Template`` instance whose exact type depends on which backend loaded it.
  1110. Both classes provide a ``render()`` method, however, the former takes a
  1111. :class:`django.template.Context` as an argument while the latter expects a
  1112. :class:`dict`. This change is enforced through a deprecation path for Django
  1113. templates.
  1114. Since it's easier to understand with examples, the :ref:`upgrade guide
  1115. <get_template-upgrade-django-18>` shows how to adapt affected code.
  1116. All this also applies to :func:`~django.template.loader.select_template()`.
  1117. :class:`~django.template.Template` and :class:`~django.template.Context` classes in template responses
  1118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1119. Some methods of :class:`~django.template.response.SimpleTemplateResponse` and
  1120. :class:`~django.template.response.TemplateResponse` accepted
  1121. :class:`django.template.Context` and :class:`django.template.Template` objects
  1122. as arguments. They should now receive :class:`dict` and backend-dependent
  1123. template objects respectively.
  1124. This also applies to the return types if you have subclassed either template
  1125. response class.
  1126. Check the :doc:`template response API documentation </ref/template-response>`
  1127. for details.
  1128. ``current_app`` argument of template-related APIs
  1129. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1130. The following functions and classes will no longer accept a ``current_app``
  1131. parameter to set an URL namespace in Django 1.10:
  1132. * ``django.shortcuts.render()``
  1133. * ``django.template.Context()``
  1134. * ``django.template.RequestContext()``
  1135. * ``django.template.response.TemplateResponse()``
  1136. Set ``request.current_app`` instead, where ``request`` is the first argument
  1137. to these functions or classes. If you're using a plain ``Context``, use a
  1138. ``RequestContext`` instead.
  1139. ``dictionary`` and ``context_instance`` arguments of rendering functions
  1140. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1141. The following functions will no longer accept the ``dictionary`` and
  1142. ``context_instance`` parameters in Django 1.10:
  1143. * ``django.shortcuts.render()``
  1144. * ``django.shortcuts.render_to_response()``
  1145. * ``django.template.loader.render_to_string()``
  1146. Use the ``context`` parameter instead. When ``dictionary`` is passed as a
  1147. positional argument, which is the most common idiom, no changes are needed.
  1148. If you're passing a :class:`~django.template.Context` in ``context_instance``,
  1149. pass a :class:`dict` in the ``context`` parameter instead. If you're passing a
  1150. :class:`~django.template.RequestContext`, pass the request separately in the
  1151. ``request`` parameter.
  1152. ``dirs`` argument of template-finding functions
  1153. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1154. The following functions will no longer accept a ``dirs`` parameter to override
  1155. ``TEMPLATE_DIRS`` in Django 1.10:
  1156. * :func:`django.template.loader.get_template()`
  1157. * :func:`django.template.loader.select_template()`
  1158. * :func:`django.shortcuts.render()`
  1159. * :func:`django.shortcuts.render_to_response()`
  1160. The parameter didn't work consistently across different template loaders and
  1161. didn't work for included templates.
  1162. ``django.template.loader.BaseLoader``
  1163. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1164. ``django.template.loader.BaseLoader`` was renamed to
  1165. ``django.template.loaders.base.Loader``. If you've written a custom template
  1166. loader that inherits ``BaseLoader``, you must inherit ``Loader`` instead.
  1167. ``django.test.utils.TestTemplateLoader``
  1168. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1169. Private API ``django.test.utils.TestTemplateLoader`` is deprecated in favor of
  1170. ``django.template.loaders.locmem.Loader`` and will be removed in Django 1.9.
  1171. .. _storage-max-length-update:
  1172. Support for the ``max_length`` argument on custom ``Storage`` classes
  1173. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1174. ``Storage`` subclasses should add ``max_length=None`` as a parameter to
  1175. :meth:`~django.core.files.storage.Storage.get_available_name` and/or
  1176. :meth:`~django.core.files.storage.Storage.save` if they override either method.
  1177. Support for storages that do not accept this argument will be removed in
  1178. Django 1.10.
  1179. ``qn`` replaced by ``compiler``
  1180. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1181. In previous Django versions, various internal ORM methods (mostly ``as_sql``
  1182. methods) accepted a ``qn`` (for "quote name") argument, which was a reference
  1183. to a function that quoted identifiers for sending to the database. In Django
  1184. 1.8, that argument has been renamed to ``compiler`` and is now a full
  1185. ``SQLCompiler`` instance. For backwards-compatibility, calling a
  1186. ``SQLCompiler`` instance performs the same name-quoting that the ``qn``
  1187. function used to. However, this backwards-compatibility shim is immediately
  1188. deprecated: you should rename your ``qn`` arguments to ``compiler``, and call
  1189. ``compiler.quote_name_unless_alias(...)`` where you previously called
  1190. ``qn(...)``.
  1191. Default value of ``RedirectView.permanent``
  1192. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1193. The default value of the
  1194. :attr:`RedirectView.permanent <django.views.generic.base.RedirectView.permanent>`
  1195. attribute will change from ``True`` to ``False`` in Django 1.9.
  1196. Using ``AuthenticationMiddleware`` without ``SessionAuthenticationMiddleware``
  1197. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1198. :class:`django.contrib.auth.middleware.SessionAuthenticationMiddleware` was
  1199. added in Django 1.7. In Django 1.7.2, its functionality was moved to
  1200. ``auth.get_user()`` and, for backwards compatibility, enabled only if
  1201. ``'django.contrib.auth.middleware.SessionAuthenticationMiddleware'`` appears in
  1202. :setting:`MIDDLEWARE_CLASSES`.
  1203. In Django 1.10, session verification will be enabled regardless of whether or not
  1204. ``SessionAuthenticationMiddleware`` is enabled (at which point
  1205. ``SessionAuthenticationMiddleware`` will have no significance). You can add it
  1206. to your ``MIDDLEWARE_CLASSES`` sometime before then to opt-in. Please read the
  1207. :ref:`upgrade considerations <session-invalidation-on-password-change>` first.
  1208. ``django.contrib.sitemaps.FlatPageSitemap``
  1209. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1210. ``django.contrib.sitemaps.FlatPageSitemap`` has moved to
  1211. ``django.contrib.flatpages.sitemaps.FlatPageSitemap``. The old import location
  1212. is deprecated and will be removed in Django 1.9.
  1213. Model ``Field.related``
  1214. ~~~~~~~~~~~~~~~~~~~~~~~
  1215. Private attribute ``django.db.models.Field.related`` is deprecated in favor
  1216. of ``Field.rel``. The latter is an instance of
  1217. ``django.db.models.fields.related.ForeignObjectRel`` which replaces
  1218. ``django.db.models.related.RelatedObject``. The ``django.db.models.related``
  1219. module has been removed and the ``Field.related`` attribute will be removed in
  1220. Django 1.10.
  1221. ``ssi`` template tag
  1222. ~~~~~~~~~~~~~~~~~~~~
  1223. The :ttag:`ssi` template tag allows files to be included in a template by
  1224. absolute path. This is of limited use in most deployment situations, and
  1225. the :ttag:`include` tag often makes more sense. This tag is now deprecated and
  1226. will be removed in Django 1.10.
  1227. ``=`` as comparison operator in ``if`` template tag
  1228. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1229. Using a single equals sign with the ``{% if %}`` template tag for equality
  1230. testing was undocumented and untested. It's now deprecated in favor of ``==``.
  1231. ``%(<foo>)s`` syntax in ``ModelFormMixin.success_url``
  1232. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1233. The legacy ``%(<foo>)s`` syntax in :attr:`ModelFormMixin.success_url
  1234. <django.views.generic.edit.ModelFormMixin.success_url>` is deprecated and
  1235. will be removed in Django 1.10.
  1236. ``GeoQuerySet`` aggregate methods
  1237. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1238. The ``collect()``, ``extent()``, ``extent3d()``, ``makeline()``, and ``union()``
  1239. aggregate methods are deprecated and should be replaced by their function-based
  1240. aggregate equivalents (``Collect``, ``Extent``, ``Extent3D``, ``MakeLine``, and
  1241. ``Union``).
  1242. .. _deprecated-signature-of-allow-migrate:
  1243. Signature of the ``allow_migrate`` router method
  1244. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1245. The signature of the :meth:`allow_migrate` method of database routers has
  1246. changed from ``allow_migrate(db, model)`` to
  1247. ``allow_migrate(db, app_label, model_name=None, **hints)``.
  1248. When ``model_name`` is set, the value that was previously given through the
  1249. ``model`` positional argument may now be found inside the ``hints`` dictionary
  1250. under the key ``'model'``.
  1251. After switching to the new signature the router will also be called by the
  1252. :class:`~django.db.migrations.operations.RunPython` and
  1253. :class:`~django.db.migrations.operations.RunSQL` operations.
  1254. .. removed-features-1.8:
  1255. Features removed in 1.8
  1256. =======================
  1257. These features have reached the end of their deprecation cycle and so have been
  1258. removed in Django 1.8 (please see the :ref:`deprecation timeline
  1259. <deprecation-removed-in-1.8>` for more details):
  1260. * ``django.contrib.comments`` is removed.
  1261. * The following transaction management APIs are removed:
  1262. - ``TransactionMiddleware``
  1263. - the decorators and context managers ``autocommit``, ``commit_on_success``,
  1264. and ``commit_manually``, defined in ``django.db.transaction``
  1265. - the functions ``commit_unless_managed`` and ``rollback_unless_managed``,
  1266. also defined in ``django.db.transaction``
  1267. - the ``TRANSACTIONS_MANAGED`` setting
  1268. * The :ttag:`cycle` and :ttag:`firstof` template tags auto-escape their
  1269. arguments.
  1270. * The ``SEND_BROKEN_LINK_EMAILS`` setting is removed.
  1271. * ``django.middleware.doc.XViewMiddleware`` is removed.
  1272. * The ``Model._meta.module_name`` alias is removed.
  1273. * The backward compatible shims introduced to rename ``get_query_set``
  1274. and similar queryset methods are removed. This affects the following classes:
  1275. ``BaseModelAdmin``, ``ChangeList``, ``BaseCommentNode``,
  1276. ``GenericForeignKey``, ``Manager``, ``SingleRelatedObjectDescriptor`` and
  1277. ``ReverseSingleRelatedObjectDescriptor``.
  1278. * The backward compatible shims introduced to rename the attributes
  1279. ``ChangeList.root_query_set`` and ``ChangeList.query_set`` are removed.
  1280. * ``django.views.defaults.shortcut`` and ``django.conf.urls.shortcut`` are
  1281. removed.
  1282. * Support for the Python Imaging Library (PIL) module is removed.
  1283. * The following private APIs are removed:
  1284. - ``django.db.backend``
  1285. - ``django.db.close_connection()``
  1286. - ``django.db.backends.creation.BaseDatabaseCreation.set_autocommit()``
  1287. - ``django.db.transaction.is_managed()``
  1288. - ``django.db.transaction.managed()``
  1289. * ``django.forms.widgets.RadioInput`` is removed.
  1290. * The module ``django.test.simple`` and the class
  1291. ``django.test.simple.DjangoTestSuiteRunner`` are removed.
  1292. * The module ``django.test._doctest`` is removed.
  1293. * The ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting is removed. This change
  1294. affects both ``django.middleware.cache.CacheMiddleware`` and
  1295. ``django.middleware.cache.UpdateCacheMiddleware`` despite the lack of a
  1296. deprecation warning in the latter class.
  1297. * Usage of the hard-coded *Hold down "Control", or "Command" on a Mac, to select
  1298. more than one.* string to override or append to user-provided ``help_text`` in
  1299. forms for ``ManyToMany`` model fields is not performed by Django anymore
  1300. either at the model or forms layer.
  1301. * The ``Model._meta.get_(add|change|delete)_permission`` methods are removed.
  1302. * The session key ``django_language`` is no longer read for backwards
  1303. compatibility.
  1304. * Geographic Sitemaps are removed
  1305. (``django.contrib.gis.sitemaps.views.index`` and
  1306. ``django.contrib.gis.sitemaps.views.sitemap``).
  1307. * ``django.utils.html.fix_ampersands``, the ``fix_ampersands`` template filter,
  1308. and ``django.utils.html.clean_html`` are removed.