1.7.txt 36 KB

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