1.7.txt 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. ============================================
  2. Django 1.7 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. Welcome to Django 1.7!
  5. These release notes cover the `new features`_, as well as some `backwards
  6. incompatible changes`_ you'll want to be aware of when upgrading from Django
  7. 1.6 or older versions. We've also dropped some features, which are detailed in
  8. :doc:`our deprecation plan </internals/deprecation>`, and we've `begun the
  9. deprecation process for some features`_.
  10. .. _`new features`: `What's new in Django 1.7`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.7`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.7`_
  13. Python compatibility
  14. ====================
  15. Django 1.7 requires Python 2.7 or above, though we **highly recommend**
  16. the latest minor release. Support for Python 2.6 has been dropped.
  17. This change should affect only a small number of Django users, as most
  18. operating-system vendors today are shipping Python 2.7 or newer as their default
  19. version. If you're still using Python 2.6, however, you'll need to stick to
  20. Django 1.6 until you can upgrade your Python version. Per :doc:`our support
  21. policy </internals/release-process>`, Django 1.6 will continue to receive
  22. security support until the release of Django 1.8.
  23. What's new in Django 1.7
  24. ========================
  25. Schema migrations
  26. ~~~~~~~~~~~~~~~~~
  27. Django now has built-in support for schema migrations. It allows models
  28. to be updated, changed, and deleted by creating migration files that represent
  29. the model changes and which can be run on any development, staging or production
  30. database.
  31. Migrations are covered in :doc:`their own documentation</topics/migrations>`,
  32. but a few of the key features are:
  33. * ``syncdb`` has been deprecated and replaced by ``migrate``. Don't worry -
  34. calls to ``syncdb`` will still work as before.
  35. * A new ``makemigrations`` command provides an easy way to autodetect changes
  36. to your models and make migrations for them.
  37. :data:`~django.db.models.signals.pre_syncdb` and
  38. :data:`~django.db.models.signals.post_syncdb` have been replaced by
  39. :data:`~django.db.models.signals.pre_migrate` and
  40. :data:`~django.db.models.signals.post_migrate` respectively. These new
  41. signals have slightly different arguments. Check the documentation for
  42. details.
  43. * The ``allow_syncdb`` method on database routers is now called ``allow_migrate``,
  44. but still performs the same function. Routers with ``allow_syncdb`` methods
  45. will still work, but that method name is deprecated and you should change
  46. it as soon as possible (nothing more than renaming is required).
  47. App-loading refactor
  48. ~~~~~~~~~~~~~~~~~~~~
  49. Historically, Django applications were tightly linked to models. A singleton
  50. known as the "app cache" dealt with both installed applications and models.
  51. The models module was used as an identifier for applications in many APIs.
  52. As the concept of :doc:`Django applications </ref/applications>` matured, this
  53. code showed some shortcomings. It has been refactored into an "app registry"
  54. where models modules no longer have a central role and where it's possible to
  55. attach configuration data to applications.
  56. Improvements thus far include:
  57. * It is possible to omit ``models.py`` entirely if an application doesn't
  58. have any models.
  59. * The name of applications can be customized in the admin with the
  60. :attr:`~django.apps.AppConfig.verbose_name` of application configurations.
  61. New method on Field subclasses
  62. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. To help power both schema migrations and composite keys, the :class:`~django.db.models.Field` API now
  64. has a new required method: ``deconstruct()``.
  65. This method takes no arguments, and returns a tuple of four items:
  66. * ``name``: The field's attribute name on its parent model, or None if it is not part of a model
  67. * ``path``: A dotted, Python path to the class of this field, including the class name.
  68. * ``args``: Positional arguments, as a list
  69. * ``kwargs``: Keyword arguments, as a dict
  70. These four values allow any field to be serialized into a file, as well as
  71. allowing the field to be copied safely, both essential parts of these new features.
  72. This change should not affect you unless you write custom Field subclasses;
  73. if you do, you may need to reimplement the ``deconstruct()`` method if your
  74. subclass changes the method signature of ``__init__`` in any way. If your
  75. field just inherits from a built-in Django field and doesn't override ``__init__``,
  76. no changes are necessary.
  77. If you do need to override ``deconstruct()``, a good place to start is the
  78. built-in Django fields (``django/db/models/fields/__init__.py``) as several
  79. fields, including ``DecimalField`` and ``DateField``, override it and show how
  80. to call the method on the superclass and simply add or remove extra arguments.
  81. Calling custom ``QuerySet`` methods from the ``Manager``
  82. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. The :meth:`QuerySet.as_manager() <django.db.models.query.QuerySet.as_manager>`
  84. class method has been added to :ref:`create Manager with QuerySet methods
  85. <create-manager-with-queryset-methods>`.
  86. Using a custom manager when traversing reverse relations
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. It is now possible to :ref:`specify a custom manager
  89. <using-custom-reverse-manager>` when traversing a reverse relationship.
  90. New ``Prefetch`` object for advanced ``prefetch_related`` operations.
  91. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. The new :class:`~django.db.models.Prefetch` object allows customizing
  93. prefetch operations.
  94. You can specify the ``QuerySet`` used to traverse a given relation
  95. or customize the storage location of prefetch results.
  96. This enables things like filtering prefetched relations, calling
  97. :meth:`~django.db.models.query.QuerySet.select_related()` from a prefetched
  98. relation, or prefetching the same relation multiple times with different
  99. querysets. See :meth:`~django.db.models.query.QuerySet.prefetch_related()`
  100. for more details.
  101. Admin shortcuts support time zones
  102. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. The "today" and "now" shortcuts next to date and time input widgets in the
  104. admin are now operating in the :ref:`current time zone
  105. <default-current-time-zone>`. Previously, they used the browser time zone,
  106. which could result in saving the wrong value when it didn't match the current
  107. time zone on the server.
  108. In addition, the widgets now display a help message when the browser and
  109. server time zone are different, to clarify how the value inserted in the field
  110. will be interpreted.
  111. Using database cursors as context managers
  112. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113. Prior to Python 2.7, database cursors could be used as a context manager. The
  114. specific backend's cursor defined the behavior of the context manager. The
  115. behavior of magic method lookups was changed with Python 2.7 and cursors were
  116. no longer usable as context managers.
  117. Django 1.7 allows a cursor to be used as a context manager that is a shortcut
  118. for the following, instead of backend specific behavior.
  119. .. code-block:: python
  120. c = connection.cursor()
  121. try:
  122. c.execute(...)
  123. finally:
  124. c.close()
  125. Minor features
  126. ~~~~~~~~~~~~~~
  127. :mod:`django.contrib.admin`
  128. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  129. * You can now implement :attr:`~django.contrib.admin.AdminSite.site_header`,
  130. :attr:`~django.contrib.admin.AdminSite.site_title`, and
  131. :attr:`~django.contrib.admin.AdminSite.index_title` attributes on a custom
  132. :class:`~django.contrib.admin.AdminSite` in order to easily change the admin
  133. site's page title and header text. No more needing to override templates!
  134. * Buttons in :mod:`django.contrib.admin` now use the ``border-radius`` CSS
  135. property for rounded corners rather than GIF background images.
  136. * Some admin templates now have ``app-<app_name>`` and ``model-<model_name>``
  137. classes in their ``<body>`` tag to allow customizing the CSS per app or per
  138. model.
  139. * The admin changelist cells now have a ``field-<field_name>`` class in the
  140. HTML to enable style customizations.
  141. * The admin's search fields can now be customized per-request thanks to the new
  142. :meth:`django.contrib.admin.ModelAdmin.get_search_fields` method.
  143. * The :meth:`ModelAdmin.get_fields()
  144. <django.contrib.admin.ModelAdmin.get_fields>` method may be overridden to
  145. customize the value of :attr:`ModelAdmin.fields
  146. <django.contrib.admin.ModelAdmin.fields>`.
  147. * In addition to the existing ``admin.site.register`` syntax, you can use the
  148. new :func:`~django.contrib.admin.register` decorator to register a
  149. :class:`~django.contrib.admin.ModelAdmin`.
  150. * You may specify :meth:`ModelAdmin.list_display_links
  151. <django.contrib.admin.ModelAdmin.list_display_links>` ``= None`` to disable
  152. links on the change list page grid.
  153. * You may now specify :attr:`ModelAdmin.view_on_site
  154. <django.contrib.admin.ModelAdmin.view_on_site>` to control whether or not to
  155. display the "View on site" link.
  156. :mod:`django.contrib.auth`
  157. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  158. * Any ``**kwargs`` passed to
  159. :meth:`~django.contrib.auth.models.User.email_user()` are passed to the
  160. underlying :meth:`~django.core.mail.send_mail()` call.
  161. * The :func:`~django.contrib.auth.decorators.permission_required` decorator can
  162. take a list of permissions as well as a single permission.
  163. * You can override the new :meth:`AuthenticationForm.confirm_login_allowed()
  164. <django.contrib.auth.forms.AuthenticationForm.confirm_login_allowed>` method
  165. to more easily customize the login policy.
  166. * :func:`django.contrib.auth.views.password_reset` takes an optional
  167. ``html_email_template_name`` parameter used to send a multipart HTML email
  168. for password resets.
  169. :mod:`django.contrib.gis`
  170. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  171. * The default OpenLayers library version included in widgets has been updated
  172. from 2.11 to 2.13.
  173. * Prepared geometries now also support the ``crosses``, ``disjoint``,
  174. ``overlaps``, ``touches`` and ``within`` predicates, if GEOS 3.3 or later is
  175. installed.
  176. :mod:`django.contrib.messages`
  177. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  178. * The backends for :mod:`django.contrib.messages` that use cookies, will now
  179. follow the :setting:`SESSION_COOKIE_SECURE` and
  180. :setting:`SESSION_COOKIE_HTTPONLY` settings.
  181. * The :ref:`messages context processor <message-displaying>` now adds a
  182. dictionary of default levels under the name ``DEFAULT_MESSAGE_LEVELS``.
  183. * :class:`~django.contrib.messages.storage.base.Message` objects now have a
  184. ``level_tag`` attribute that contains the string representation of the
  185. message level.
  186. :mod:`django.contrib.redirects`
  187. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  188. * :class:`~django.contrib.redirects.middleware.RedirectFallbackMiddleware`
  189. has two new attributes
  190. (:attr:`~django.contrib.redirects.middleware.RedirectFallbackMiddleware.response_gone_class`
  191. and
  192. :attr:`~django.contrib.redirects.middleware.RedirectFallbackMiddleware.response_redirect_class`)
  193. that specify the types of :class:`~django.http.HttpResponse` instances the
  194. middleware returns.
  195. :mod:`django.contrib.sessions`
  196. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  197. * The ``"django.contrib.sessions.backends.cached_db"`` session backend now
  198. respects :setting:`SESSION_CACHE_ALIAS`. In previous versions, it always used
  199. the `default` cache.
  200. :mod:`django.contrib.sitemaps`
  201. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  202. * The :mod:`sitemap framework<django.contrib.sitemaps>` now makes use of
  203. :attr:`~django.contrib.sitemaps.Sitemap.lastmod` to set a ``Last-Modified``
  204. header in the response. This makes it possible for the
  205. :class:`~django.middleware.http.ConditionalGetMiddleware` to handle
  206. conditional ``GET`` requests for sitemaps which set ``lastmod``.
  207. :mod:`django.contrib.staticfiles`
  208. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  209. * The :ref:`static files storage classes <staticfiles-storages>` may be
  210. subclassed to override the permissions that collected static files and
  211. directories receive by setting the
  212. :attr:`~django.core.files.storage.FileSystemStorage.file_permissions_mode`
  213. and :attr:`~django.core.files.storage.FileSystemStorage.directory_permissions_mode`
  214. parameters. See :djadmin:`collectstatic` for example usage.
  215. :mod:`django.contrib.syndication`
  216. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  217. * The :class:`~django.utils.feedgenerator.Atom1Feed` syndication feed's
  218. ``updated`` element now utilizes ``updateddate`` instead of ``pubdate``,
  219. allowing the ``published`` element to be included in the feed (which
  220. relies on ``pubdate``).
  221. Cache
  222. ^^^^^
  223. * Access to caches configured in :setting:`CACHES` is now available via
  224. :data:`django.core.cache.caches`. This dict-like object provides a different
  225. instance per thread. It supersedes :func:`django.core.cache.get_cache` which
  226. is now deprecated.
  227. * If you instanciate cache backends directly, be aware that they aren't
  228. thread-safe any more, as :data:`django.core.cache.caches` now yields
  229. different instances per thread.
  230. Email
  231. ^^^^^
  232. * :func:`~django.core.mail.send_mail` now accepts an ``html_message``
  233. parameter for sending a multipart ``text/plain`` and ``text/html`` email.
  234. * The SMTP :class:`~django.core.mail.backends.smtp.EmailBackend` now accepts a
  235. :attr:`~django.core.mail.backends.smtp.EmailBackend.timeout` parameter.
  236. File Uploads
  237. ^^^^^^^^^^^^
  238. * The new :attr:`UploadedFile.content_type_extra
  239. <django.core.files.uploadedfile.UploadedFile.content_type_extra>` attribute
  240. contains extra parameters passed to the ``content-type`` header on a file
  241. upload.
  242. * The new :setting:`FILE_UPLOAD_DIRECTORY_PERMISSIONS` setting controls
  243. the file system permissions of directories created during file upload, like
  244. :setting:`FILE_UPLOAD_PERMISSIONS` does for the files themselves.
  245. * The :attr:`FileField.upload_to <django.db.models.FileField.upload_to>`
  246. attribute is now optional. If it is omitted or given ``None`` or an empty
  247. string, a subdirectory won't be used for storing the uploaded files.
  248. Forms
  249. ^^^^^
  250. * The ``<label>`` and ``<input>`` tags rendered by
  251. :class:`~django.forms.RadioSelect` and
  252. :class:`~django.forms.CheckboxSelectMultiple` when looping over the radio
  253. buttons or checkboxes now include ``for`` and ``id`` attributes, respectively.
  254. Each radio button or checkbox includes an ``id_for_label`` attribute to
  255. output the element's ID.
  256. * :attr:`Field.choices<django.db.models.Field.choices>` now allows you to
  257. customize the "empty choice" label by including a tuple with an empty string
  258. or ``None`` for the key and the custom label as the value. The default blank
  259. option ``"----------"`` will be omitted in this case.
  260. * :class:`~django.forms.MultiValueField` allows optional subfields by setting
  261. the ``require_all_fields`` argument to ``False``. The ``required`` attribute
  262. for each individual field will be respected, and a new ``incomplete``
  263. validation error will be raised when any required fields are empty.
  264. * The :meth:`~django.forms.Form.clean` method on a form no longer needs to
  265. return ``self.cleaned_data``. If it does return a changed dictionary then
  266. that will still be used.
  267. * After a temporary regression in Django 1.6, it's now possible again to make
  268. :class:`~django.forms.TypedChoiceField` ``coerce`` method return an arbitrary
  269. value.
  270. * :attr:`SelectDateWidget.months
  271. <django.forms.extras.widgets.SelectDateWidget.months>` can be used to
  272. customize the wording of the months displayed in the select widget.
  273. * The ``min_num`` and ``validate_min`` parameters were added to
  274. :func:`~django.forms.formsets.formset_factory` to allow validating
  275. a minimum number of submitted forms.
  276. * The metaclasses used by ``Form`` and ``ModelForm`` have been reworked to
  277. support more inheritance scenarios. The previous limitation that prevented
  278. inheriting from both ``Form`` and ``ModelForm`` simultaneously have been
  279. removed as long as ``ModelForm`` appears first in the MRO.
  280. * It's now possible to opt-out from a ``Form`` field declared in a parent class
  281. by shadowing it with a non-``Field`` value.
  282. * The new :meth:`~django.forms.Form.add_error()` method allows adding errors
  283. to specific form fields.
  284. * The dict-like attribute :attr:`~django.forms.Form.errors` now has two new
  285. methods :meth:`~django.forms.Form.errors.as_data()` and
  286. :meth:`~django.forms.Form.errors.as_json()`. The former returns a ``dict``
  287. that maps fields to their original errors, complete with all metadata
  288. (error code and params), the latter returns the errors serialized as json.
  289. Internationalization
  290. ^^^^^^^^^^^^^^^^^^^^
  291. * The :attr:`django.middleware.locale.LocaleMiddleware.response_redirect_class`
  292. attribute allows you to customize the redirects issued by the middleware.
  293. * The :class:`~django.middleware.locale.LocaleMiddleware` now stores the user's
  294. selected language with the session key ``_language``. Previously it was
  295. stored with the key ``django_language``, but keys reserved for Django should
  296. start with an underscore. For backwards compatibility ``django_language`` is
  297. still read from in 1.7. Sessions will be migrated to the new ``_language``
  298. key as they are written.
  299. * The :ttag:`blocktrans` now supports a ``trimmed`` option. This
  300. option will remove newline characters from the beginning and the end of the
  301. content of the ``{% blocktrans %}`` tag, replace any whitespace at the
  302. beginning and end of a line and merge all lines into one using a space
  303. character to separate them. This is quite useful for indenting the content of
  304. a ``{% blocktrans %}`` tag without having the indentation characters end up
  305. in the corresponding entry in the PO file, which makes the translation
  306. process easier.
  307. * When you run :djadmin:`makemessages` from the root directory of your project,
  308. any extracted strings will now be automatically distributed to the proper
  309. app or project message file. See :ref:`how-to-create-language-files` for
  310. details.
  311. Management Commands
  312. ^^^^^^^^^^^^^^^^^^^
  313. * The :djadminopt:`--no-color` option for ``django-admin.py`` allows you to
  314. disable the colorization of management command output.
  315. * The new :djadminopt:`--natural-foreign` and :djadminopt:`--natural-primary`
  316. options for :djadmin:`dumpdata`, and the new ``use_natural_foreign_keys`` and
  317. ``use_natural_primary_keys`` arguments for ``serializers.serialize()``, allow
  318. the use of natural primary keys when serializing.
  319. * It is no longer necessary to provide the cache table name or the
  320. :djadminopt:`--database` option for the :djadmin:`createcachetable` command.
  321. Django takes this information from your settings file. If you have configured
  322. multiple caches or multiple databases, all cache tables are created.
  323. * The :djadmin:`runserver` command received several improvements:
  324. * On Linux systems, if pyinotify_ is installed, the development server will
  325. reload immediately when a file is changed. Previously, it polled the
  326. filesystem for changes every second. That caused a small delay before
  327. reloads and reduced battery life on laptops.
  328. .. _pyinotify: https://pypi.python.org/pypi/pyinotify
  329. * In addition, the development server automatically reloads when a
  330. translation file is updated, i.e. after running
  331. :djadmin:`compilemessages`.
  332. * All HTTP requests are logged to the console, including requests for static
  333. files or ``favicon.ico`` that used to be filtered out.
  334. * Management commands can now produce syntax colored output under Windows if
  335. the ANSICON third-party tool is installed and active.
  336. Models
  337. ^^^^^^
  338. * The :meth:`QuerySet.update_or_create()
  339. <django.db.models.query.QuerySet.update_or_create>` method was added.
  340. * The new :attr:`~django.db.models.Options.default_permissions` model
  341. ``Meta`` option allows you to customize (or disable) creation of the default
  342. add, change, and delete permissions.
  343. * :attr:`~django.db.models.Options.app_label` is no longer required for models
  344. that are defined in a ``models`` package within an app.
  345. * Explicit :class:`~django.db.models.OneToOneField` for
  346. :ref:`multi-table-inheritance` are now discovered in abstract classes.
  347. * Is it now possible to avoid creating a backward relation for
  348. :class:`~django.db.models.OneToOneField` by setting its
  349. :attr:`~django.db.models.ForeignKey.related_name` to
  350. ``'+'`` or ending it with ``'+'``.
  351. * :class:`F expressions <django.db.models.F>` support the power operator
  352. (``**``).
  353. * The ``remove()`` and ``clear()`` methods of the related managers created by
  354. ``ForeignKey`` and ``GenericForeignKey`` now accept the ``bulk`` keyword
  355. argument to control whether or not to perform operations in bulk
  356. (i.e. using ``QuerySet.update()``). Defaults to ``True``.
  357. * It is now possible to use ``None`` as a query value for the :lookup:`iexact`
  358. lookup.
  359. Signals
  360. ^^^^^^^
  361. * The ``enter`` argument was added to the
  362. :data:`~django.test.signals.setting_changed` signal.
  363. * The model signals can be now be connected to using a ``str`` of the
  364. ``'app_label.ModelName'`` form – just like related fields – to lazily
  365. reference their senders.
  366. Templates
  367. ^^^^^^^^^
  368. * The :meth:`Context.push() <django.template.Context.push>` method now returns
  369. a context manager which automatically calls :meth:`pop()
  370. <django.template.Context.pop>` upon exiting the ``with`` statement.
  371. Additionally, :meth:`push() <django.template.Context.push>` now accepts
  372. parameters that are passed to the ``dict`` constructor used to build the new
  373. context level.
  374. * The :ttag:`widthratio` template tag now accepts an "as" parameter to capture
  375. the result in a variable.
  376. * The :ttag:`include` template tag will now also accept anything with a
  377. ``render()`` method (such as a ``Template``) as an argument. String
  378. arguments will be looked up using
  379. :func:`~django.template.loader.get_template` as always.
  380. * It is now possible to :ttag:`include` templates recursively.
  381. * Template objects now have an origin attribute set when
  382. :setting:`TEMPLATE_DEBUG` is ``True``. This allows template origins to be
  383. inspected and logged outside of the ``django.template`` infrastructure.
  384. * ``TypeError`` exceptions are no longer silenced when raised during the
  385. rendering of a template.
  386. * The following functions now accept a ``dirs`` parameter which is a list or
  387. tuple to override :setting:`TEMPLATE_DIRS`:
  388. * :func:`django.template.loader.get_template()`
  389. * :func:`django.template.loader.select_template()`
  390. * :func:`django.shortcuts.render()`
  391. * :func:`django.shortcuts.render_to_response()`
  392. * The :tfilter:`time` filter now accepts timzone-related :ref:`format
  393. specifiers <date-and-time-formatting-specifiers>` ``'e'``, ``'O'`` , ``'T'``
  394. and ``'Z'`` and is able to digest :ref:`time-zone-aware
  395. <naive_vs_aware_datetimes>` ``datetime`` instances performing the expected
  396. rendering.
  397. * The :ttag:`cache` tag will now try to use the cache called
  398. "template_fragments" if it exists and fall back to using the default cache
  399. otherwise. It also now accepts an optional ``using`` keyword argument to
  400. control which cache it uses.
  401. Requests
  402. ^^^^^^^^
  403. * The new :attr:`HttpRequest.scheme <django.http.HttpRequest.scheme>` attribute
  404. specifies the scheme of the request (``http`` or ``https`` normally).
  405. Tests
  406. ^^^^^
  407. * :class:`~django.test.runner.DiscoverRunner` has two new attributes,
  408. :attr:`~django.test.runner.DiscoverRunner.test_suite` and
  409. :attr:`~django.test.runner.DiscoverRunner.test_runner`, which facilitate
  410. overriding the way tests are collected and run.
  411. * The ``fetch_redirect_response`` argument was added to
  412. :meth:`~django.test.SimpleTestCase.assertRedirects`. Since the test
  413. client can't fetch externals URLs, this allows you to use ``assertRedirects``
  414. with redirects that aren't part of your Django app.
  415. * Correct handling of scheme when making comparisons in
  416. :meth:`~django.test.SimpleTestCase.assertRedirects`.
  417. * The ``secure`` argument was added to all the request methods of
  418. :class:`~django.test.Client`. If ``True``, the request will be made
  419. through HTTPS.
  420. * Requests made with :meth:`Client.login() <django.test.Client.login>` and
  421. :meth:`Client.logout() <django.test.Client.logout>` respect defaults defined
  422. in :class:`~django.test.Client` instantiation and are processed through
  423. middleware.
  424. * :meth:`~django.test.TransactionTestCase.assertNumQueries` now prints
  425. out the list of executed queries if the assertion fails.
  426. Validators
  427. ^^^^^^^^^^
  428. * :class:`~django.core.validators.URLValidator` now accepts an optional
  429. ``schemes`` argument which allows customization of the accepted URI schemes
  430. (instead of the defaults ``http(s)`` and ``ftp(s)``).
  431. Backwards incompatible changes in 1.7
  432. =====================================
  433. .. warning::
  434. In addition to the changes outlined in this section, be sure to review the
  435. :doc:`deprecation plan </internals/deprecation>` for any features that
  436. have been removed. If you haven't updated your code within the
  437. deprecation timeline for a given feature, its removal may appear as a
  438. backwards incompatible change.
  439. allow_syncdb/allow_migrate
  440. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  441. While Django will still look at ``allow_syncdb`` methods even though they
  442. should be renamed to ``allow_migrate``, there is a subtle difference in which
  443. models get passed to these methods.
  444. For apps with migrations, ``allow_migrate`` will now get passed
  445. :ref:`historical models <historical-models>`, which are special versioned models
  446. without custom attributes, methods or managers. Make sure your ``allow_migrate``
  447. methods are only referring to fields or other items in ``model._meta``.
  448. App-loading changes
  449. ~~~~~~~~~~~~~~~~~~~
  450. You should make sure that your project doesn't import models from applications
  451. that aren't in :setting:`INSTALLED_APPS`. Relations involving such models may
  452. not be created properly.
  453. Subclasses of :class:`~django.core.management.AppCommand` must now implement a
  454. :meth:`~django.core.management.AppCommand.handle_app_config` method instead of
  455. ``handle_app()``. This method receives an :class:`~django.apps.AppConfig` instance.
  456. Since :setting:`INSTALLED_APPS` now supports application configuration classes
  457. in addition to application modules, you should review code that accesses this
  458. setting directly and use the app registry (:attr:`django.apps.apps`) instead.
  459. The "app registry" that manages the list of installed applications doesn't
  460. have the same features as the old "app cache". Even though the "app cache" was
  461. a private API, obsolete methods will be removed after a standard deprecation
  462. period. In addition, the following changes take effect immediately:
  463. * ``get_model`` raises :exc:`~exceptions.LookupError` instead of returning
  464. ``None`` when no model is found.
  465. * The ``only_installed`` argument of ``get_model`` and ``get_models`` no
  466. longer exists, nor does the ``seed_cache`` argument of ``get_model``.
  467. While the new implementation is believed to be more robust, regressions cannot
  468. be ruled out, especially during the import sequence. Circular imports that
  469. didn't happen with previous versions of Django might appear.
  470. Behavior of ``LocMemCache`` regarding pickle errors
  471. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  472. An inconsistency existed in previous versions of Django regarding how pickle
  473. errors are handled by different cache backends.
  474. ``django.core.cache.backends.locmem.LocMemCache`` used to fail silently when
  475. such an error occurs, which is inconsistent with other backends and leads to
  476. cache-specific errors. This has been fixed in Django 1.7, see
  477. `Ticket #21200`_ for more details.
  478. .. _Ticket #21200: https://code.djangoproject.com/ticket/21200
  479. Cache keys are now generated from the request's absolute URL
  480. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  481. Previous versions of Django generated cache keys using a request's path and
  482. query string but not the scheme or host. If a Django application was serving
  483. multiple subdomains or domains, cache keys could collide. In Django 1.7, cache
  484. keys vary by the absolute URL of the request including scheme, host, path, and
  485. query string. For example, the URL portion of a cache key is now generated from
  486. ``http://www.example.com/path/to/?key=val`` rather than ``/path/to/?key=val``.
  487. The cache keys generated by Django 1.7 will be different from the keys
  488. generated by older versions of Django. After upgrading to Django 1.7, the first
  489. request to any previously cached URL will be a cache miss .
  490. Passing ``None`` to ``Manager.db_manager()``
  491. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  492. In previous versions of Django, it was possible to use
  493. ``db_manager(using=None)`` on a model manager instance to obtain a manager
  494. instance using default routing behavior, overriding any manually specified
  495. database routing. In Django 1.7, a value of ``None`` passed to db_manager will
  496. produce a router that *retains* any manually assigned database routing -- the
  497. manager will *not* be reset. This was necessary to resolve an inconsistency in
  498. the way routing information cascaded over joins. See `Ticket #13724`_ for more
  499. details.
  500. .. _Ticket #13724: https://code.djangoproject.com/ticket/13724
  501. pytz may be required
  502. ~~~~~~~~~~~~~~~~~~~~
  503. If your project handles datetimes before 1970 or after 2037 and Django raises
  504. a :exc:`~exceptions.ValueError` when encountering them, you will have to
  505. install pytz_. You may be affected by this problem if you use Django's time
  506. zone-related date formats or :mod:`django.contrib.syndication`.
  507. ``remove()`` and ``clear()`` methods of related managers
  508. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  509. The ``remove()`` and ``clear()`` methods of the related managers created by
  510. ``ForeignKey``, ``GenericForeignKey``, and ``ManyToManyField`` suffered from a
  511. number of issues. Some operations ran multiple data modifying queries without
  512. wrapping them in a transaction, and some operations didn't respect default
  513. filtering when it was present (i.e. when the default manager on the related
  514. model implemented a custom ``get_queryset()``).
  515. Fixing the issues introduced some backward incompatible changes:
  516. - The default implementation of ``remove()`` for ``ForeignKey`` related managers
  517. changed from a series of ``Model.save()`` calls to a single
  518. ``QuerySet.update()`` call. The change means that ``pre_save`` and
  519. ``post_save`` signals aren't sent anymore. You can use the ``bulk=False``
  520. keyword argument to revert to the previous behavior.
  521. - The ``remove()`` and ``clear()`` methods for ``GenericForeignKey`` related
  522. managers now perform bulk delete. The ``Model.delete()`` method isn't called
  523. on each instance anymore. You can use the ``bulk=False`` keyword argument to
  524. revert to the previous behavior.
  525. - The ``remove()`` and ``clear()`` methods for ``ManyToManyField`` related
  526. managers perform nested queries when filtering is involved, which may or
  527. may not be an issue depending on your database and your data itself.
  528. See :ref:`this note <nested-queries-performance>` for more details.
  529. .. _pytz: https://pypi.python.org/pypi/pytz/
  530. Miscellaneous
  531. ~~~~~~~~~~~~~
  532. * The :meth:`django.core.files.uploadhandler.FileUploadHandler.new_file()`
  533. method is now passed an additional ``content_type_extra`` parameter. If you
  534. have a custom :class:`~django.core.files.uploadhandler.FileUploadHandler`
  535. that implements ``new_file()``, be sure it accepts this new parameter.
  536. * :class:`ModelFormSet<django.forms.models.BaseModelFormSet>`’s no longer
  537. delete instances when ``save(commit=False)`` is called. See
  538. :attr:`~django.forms.formsets.BaseFormSet.can_delete` for instructions on how
  539. to manually delete objects from deleted forms.
  540. * Loading empty fixtures emits a ``RuntimeWarning`` rather than raising
  541. :class:`~django.core.management.CommandError`.
  542. * :func:`django.contrib.staticfiles.views.serve` will now raise an
  543. :exc:`~django.http.Http404` exception instead of
  544. :exc:`~django.core.exceptions.ImproperlyConfigured` when :setting:`DEBUG`
  545. is ``False``. This change removes the need to conditionally add the view to
  546. your root URLconf, which in turn makes it safe to reverse by name. It also
  547. removes the ability for visitors to generate spurious HTTP 500 errors by
  548. requesting static files that don't exist or haven't been collected yet.
  549. * The :meth:`django.db.models.Model.__eq__` method is now defined in a
  550. way where instances of a proxy model and its base model are considered
  551. equal when primary keys match. Previously only instances of exact same
  552. class were considered equal on primary key match.
  553. * The :meth:`django.db.models.Model.__eq__` method has changed such that
  554. two ``Model`` instances without primary key values won't be considered
  555. equal (unless they are the same instance).
  556. * The :meth:`django.db.models.Model.__hash__` will now raise ``TypeError``
  557. when called on an instance without a primary key value. This is done to
  558. avoid mutable ``__hash__`` values in containers.
  559. * :class:`~django.db.models.AutoField` columns in SQLite databases will now be
  560. created using the ``AUTOINCREMENT`` option, which guarantees monotonic
  561. increments. This will cause primary key numbering behavior to change on
  562. SQLite, becoming consistent with most other SQL databases. This will only
  563. apply to newly created tables. If you have a database created with an older
  564. version of Django, you will need to migrate it to take advantage of this
  565. feature. For example, you could do the following:
  566. #) Use :djadmin:`dumpdata` to save your data.
  567. #) Rename the existing database file (keep it as a backup).
  568. #) Run :djadmin:`migrate` to create the updated schema.
  569. #) Use :djadmin:`loaddata` to import the fixtures you exported in (1).
  570. * ``django.contrib.auth.models.AbstractUser`` no longer defines a
  571. :meth:`~django.db.models.Model.get_absolute_url()` method. The old definition
  572. returned ``"/users/%s/" % urlquote(self.username)`` which was arbitrary
  573. since applications may or may not define such a url in ``urlpatterns``.
  574. Define a ``get_absolute_url()`` method on your own custom user object or use
  575. :setting:`ABSOLUTE_URL_OVERRIDES` if you want a URL for your user.
  576. * The static asset-serving functionality of the
  577. :class:`django.test.LiveServerTestCase` class has been simplified: Now it's
  578. only able to serve content already present in :setting:`STATIC_ROOT` when
  579. tests are run. The ability to transparently serve all the static assets
  580. (similarly to what one gets with :setting:`DEBUG = True <DEBUG>` at
  581. development-time) has been moved to a new class that lives in the
  582. ``staticfiles`` application (the one actually in charge of such feature):
  583. :class:`django.contrib.staticfiles.testing.StaticLiveServerCase`. In other
  584. words, ``LiveServerTestCase`` itself is less powerful but at the same time
  585. has less magic.
  586. Rationale behind this is removal of dependency of non-contrib code on
  587. contrib applications.
  588. * The old cache URI syntax (e.g. ``"locmem://"``) is no longer supported. It
  589. still worked, even though it was not documented or officially supported. If
  590. you're still using it, please update to the current :setting:`CACHES` syntax.
  591. * The default ordering of ``Form`` fields in case of inheritance has changed to
  592. follow normal Python MRO. Fields are now discovered by iterating through the
  593. MRO in reverse with the topmost class coming last. This only affects you if
  594. you relied on the default field ordering while having fields defined on both
  595. the current class *and* on a parent ``Form``.
  596. * The ``required`` argument of
  597. :class:`~django.forms.extras.widgets.SelectDateWidget` has been removed.
  598. This widget now respects the form field's ``is_required`` attribute like
  599. other widgets.
  600. * :meth:`~django.db.models.query.QuerySet.select_related` now chains in the
  601. same way as other similar calls like ``prefetch_related``. That is,
  602. ``select_related('foo', 'bar')`` is equivalent to
  603. ``select_related('foo').select_related('bar')``. Previously the latter would
  604. have been equivalent to ``select_related('bar')``.
  605. * GeoDjango dropped support for GEOS < 3.1.
  606. Features deprecated in 1.7
  607. ==========================
  608. ``django.core.cache.get_cache``
  609. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  610. :func:`django.core.cache.get_cache` has been supplanted by
  611. :data:`django.core.cache.caches`.
  612. ``django.utils.dictconfig``/``django.utils.importlib``
  613. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  614. ``django.utils.dictconfig`` and ``django.utils.importlib`` were copies of
  615. respectively :mod:`logging.config` and :mod:`importlib` provided for Python
  616. versions prior to 2.7. They have been deprecated.
  617. ``django.utils.tzinfo``
  618. ~~~~~~~~~~~~~~~~~~~~~~~
  619. ``django.utils.tzinfo`` provided two :class:`~datetime.tzinfo` subclasses,
  620. ``LocalTimezone`` and ``FixedOffset``. They've been deprecated in favor of
  621. more correct alternatives provided by :mod:`django.utils.timezone`,
  622. :func:`django.utils.timezone.get_default_timezone` and
  623. :func:`django.utils.timezone.get_fixed_timezone`.
  624. ``django.utils.unittest``
  625. ~~~~~~~~~~~~~~~~~~~~~~~~~
  626. ``django.utils.unittest`` provided uniform access to the ``unittest2`` library
  627. on all Python versions. Since ``unittest2`` became the standard library's
  628. :mod:`unittest` module in Python 2.7, and Django 1.7 drops support for older
  629. Python versions, this module isn't useful anymore. It has been deprecated. Use
  630. :mod:`unittest` instead.
  631. ``django.utils.datastructures.SortedDict``
  632. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  633. As :class:`~collections.OrderedDict` was added to the standard library in
  634. Python 2.7, :class:`~django.utils.datastructures.SortedDict` is no longer
  635. needed and has been deprecated.
  636. Custom SQL location for models package
  637. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  638. Previously, if models were organized in a package (``myapp/models/``) rather
  639. than simply ``myapp/models.py``, Django would look for :ref:`initial SQL data
  640. <initial-sql>` in ``myapp/models/sql/``. This bug has been fixed so that Django
  641. will search ``myapp/sql/`` as documented. The old location will continue to
  642. work until Django 1.9.
  643. ``declared_fieldsets`` attribute on ``ModelAdmin``
  644. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  645. ``ModelAdmin.declared_fieldsets`` has been deprecated. Despite being a private
  646. API, it will go through a regular deprecation path. This attribute was mostly
  647. used by methods that bypassed ``ModelAdmin.get_fieldsets()`` but this was
  648. considered a bug and has been addressed.
  649. ``syncdb``
  650. ~~~~~~~~~~
  651. The ``syncdb`` command has been deprecated in favour of the new ``migrate``
  652. command. ``migrate`` takes the same arguments as ``syncdb`` used to plus a few
  653. more, so it's safe to just change the name you're calling and nothing else.
  654. ``util`` modules renamed to ``utils``
  655. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  656. The following instances of ``util.py`` in the Django codebase have been renamed
  657. to ``utils.py`` in an effort to unify all util and utils references:
  658. * ``django.contrib.admin.util``
  659. * ``django.contrib.gis.db.backends.util``
  660. * ``django.db.backends.util``
  661. * ``django.forms.util``
  662. ``get_formsets`` method on ``ModelAdmin``
  663. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  664. ``ModelAdmin.get_formsets`` has been deprecated in favor of the new
  665. :meth:`~django.contrib.admin.ModelAdmin.get_formsets_with_inlines`, in order to
  666. better handle the case of selecting showing inlines on a ``ModelAdmin``.
  667. ``IPAddressField``
  668. ~~~~~~~~~~~~~~~~~~
  669. The :class:`django.db.models.IPAddressField` and
  670. :class:`django.forms.IPAddressField` fields have been deprecated in favor of
  671. :class:`django.db.models.GenericIPAddressField` and
  672. :class:`django.forms.GenericIPAddressField`.
  673. ``BaseMemcachedCache._get_memcache_timeout`` method
  674. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  675. The ``BaseMemcachedCache._get_memcache_timeout()`` method has been renamed to
  676. ``get_backend_timeout()``. Despite being a private API, it will go through the
  677. normal deprecation.
  678. Natural key serialization options
  679. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  680. The ``--natural`` and ``-n`` options for :djadmin:`dumpdata` have been
  681. deprecated. Use :djadminopt:`--natural-foreign` instead.
  682. Similarly, the ``use_natural_keys`` argument for ``serializers.serialize()``
  683. has been deprecated. Use ``use_natural_foreign_keys`` instead.
  684. Merging of ``POST`` and ``GET`` arguments into ``WSGIRequest.REQUEST``
  685. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  686. It was already strongly suggested that you use ``GET`` and ``POST`` instead of
  687. ``REQUEST``, because the former are more explicit. The property ``REQUEST`` is
  688. deprecated and will be removed in Django 1.9.
  689. ``django.utils.datastructures.MergeDict`` class
  690. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  691. ``MergeDict`` exists primarily to support merging ``POST`` and ``GET``
  692. arguments into a ``REQUEST`` property on ``WSGIRequest``. To merge
  693. dictionaries, use ``dict.update()`` instead. The class ``MergeDict`` is
  694. deprecated and will be removed in Django 1.9.
  695. Language codes ``zh-cn``, ``zh-tw`` and ``fy-nl``
  696. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  697. The currently used language codes for Simplified Chinese ``zh-cn``,
  698. Traditional Chinese ``zh-tw`` and (Western) Frysian ``fy-nl`` are deprecated
  699. and should be replaced by the language codes ``zh-hans``, ``zh-hant`` and
  700. ``fy`` respectively. If you use these language codes, you should rename the
  701. locale directories and update your settings to reflect these changes. The
  702. deprecated language codes will be removed in Django 1.9.
  703. ``django.utils.functional.memoize`` function
  704. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  705. The function ``memoize`` is deprecated and should be replaced by the
  706. ``functools.lru_cache`` decorator (available from Python 3.2 onwards).
  707. Django ships a backport of this decorator for older Python versions and it's
  708. available at ``django.utils.lru_cache.lru_cache``. The deprecated function will
  709. be removed in Django 1.9.
  710. Geo Sitemaps
  711. ~~~~~~~~~~~~
  712. Google has retired support for the Geo Sitemaps format. Hence Django support
  713. for Geo Sitemaps is deprecated and will be removed in Django 1.8.
  714. Passing callable arguments to queryset methods
  715. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  716. Callable arguments for querysets were an undocumented feature that was
  717. unreliable. It's been deprecated and will be removed in Django 1.9.
  718. Callable arguments were evaluated when a queryset was constructed rather than
  719. when it was evaluated, thus this feature didn't offer any benefit compared to
  720. evaluating arguments before passing them to queryset and created confusion that
  721. the arguments may have been evaluated at query time.
  722. ``ADMIN_FOR`` setting
  723. ~~~~~~~~~~~~~~~~~~~~~
  724. The ``ADMIN_FOR`` feature, part of the admindocs, has been removed. You can
  725. remove the setting from your configuration at your convenience.