1.7.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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, which allows models
  28. to be updated, changed and deleted and the changes stored into migration files
  29. and then run on any deployed database.
  30. Migrations are covered in :doc:`their own documentation</topics/migrations>`,
  31. but a few of the key features are:
  32. * ``syncdb`` has been deprecated and replaced by ``migrate``. Don't worry -
  33. calls to ``syncdb`` will still work as before.
  34. * A new ``makemigrations`` command provides an easy way to autodetect changes
  35. to your models and make migrations for them.
  36. * :data:`~django.db.models.signals.post_syncdb` and
  37. :data:`~django.db.models.signals.post_syncdb` have been renamed to
  38. :data:`~django.db.models.signals.pre_migrate` and
  39. :data:`~django.db.models.signals.post_migrate` respectively. The
  40. ``create_models``/``created_models`` argument has also been deprecated.
  41. * The ``allow_syncdb`` method on database routers is now called ``allow_migrate``,
  42. but still performs the same function. Routers with ``allow_syncdb`` methods
  43. will still work, but that method name is deprecated and you should change
  44. it as soon as possible (nothing more than renaming is required).
  45. New method on Field subclasses
  46. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. To help power both schema migrations and composite keys, the Field API now
  48. has a new required method: ``deconstruct()``.
  49. This method takes no arguments, and returns a tuple of four items:
  50. * ``name``: The field's attribute name on its parent model, or None if it is not part of a model
  51. * ``path``: A dotted, Python path to the class of this field, including the class name.
  52. * ``args``: Positional arguments, as a list
  53. * ``kwargs``: Keyword arguments, as a dict
  54. These four values allow any field to be serialized into a file, as well as
  55. allowing the field to be copied safely, both essential parts of these new features.
  56. This change should not affect you unless you write custom Field subclasses;
  57. if you do, you may need to reimplement the ``deconstruct()`` method if your
  58. subclass changes the method signature of ``__init__`` in any way. If your
  59. field just inherits from a built-in Django field and doesn't override ``__init__``,
  60. no changes are necessary.
  61. If you do need to override ``deconstruct()``, a good place to start is the
  62. built-in Django fields (``django/db/models/fields/__init__.py``) as several
  63. fields, including ``DecimalField`` and ``DateField``, override it and show how
  64. to call the method on the superclass and simply add or remove extra arguments.
  65. Calling custom ``QuerySet`` methods from the ``Manager``
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. The :meth:`QuerySet.as_manager() <django.db.models.query.QuerySet.as_manager>`
  68. class method has been added to :ref:`create Manager with QuerySet methods
  69. <create-manager-with-queryset-methods>`.
  70. Admin shortcuts support time zones
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. The "today" and "now" shortcuts next to date and time input widgets in the
  73. admin are now operating in the :ref:`current time zone
  74. <default-current-time-zone>`. Previously, they used the browser time zone,
  75. which could result in saving the wrong value when it didn't match the current
  76. time zone on the server.
  77. In addition, the widgets now display a help message when the browser and
  78. server time zone are different, to clarify how the value inserted in the field
  79. will be interpreted.
  80. Minor features
  81. ~~~~~~~~~~~~~~
  82. * The new :attr:`UploadedFile.content_type_extra
  83. <django.core.files.uploadedfile.UploadedFile.content_type_extra>` attribute
  84. contains extra parameters passed to the ``content-type`` header on a file
  85. upload.
  86. * The ``enter`` argument was added to the
  87. :data:`~django.test.signals.setting_changed` signal.
  88. * The :meth:`QuerySet.update_or_create()
  89. <django.db.models.query.QuerySet.update_or_create>` method was added.
  90. * :attr:`~django.db.models.Options.app_label` is no longer required for models
  91. that are defined in a ``models`` package within an app.
  92. * The :meth:`Context.push() <django.template.Context.push>` method now returns
  93. a context manager which automatically calls :meth:`pop()
  94. <django.template.Context.pop>` upon exiting the ``with`` statement.
  95. Additionally, :meth:`push() <django.template.Context.push>` now accepts
  96. parameters that are passed to the ``dict`` constructor used to build the new
  97. context level.
  98. * The :class:`~django.utils.feedgenerator.Atom1Feed` syndication feed's
  99. ``updated`` element now utilizes `updateddate` instead of ``pubdate``,
  100. allowing the ``published`` element to be included in the feed (which
  101. relies on ``pubdate``).
  102. * Buttons in :mod:`django.contrib.admin` now use the ``border-radius`` CSS
  103. property for rounded corners rather than GIF background images.
  104. * Some admin templates now have ``app-<app_name>`` and ``model-<model_name>``
  105. classes in their ``<body>`` tag to allow customizing the CSS per app or per
  106. model.
  107. * The admin changelist cells now have a ``field-<field_name>`` class in the
  108. HTML to enable style customizations.
  109. * :func:`~django.core.mail.send_mail` now accepts an ``html_message``
  110. parameter for sending a multipart ``text/plain`` and ``text/html`` email.
  111. * The :djadminopt:`--no-color` option for ``django-admin.py`` allows you to
  112. disable the colorization of management command output.
  113. * The :mod:`sitemap framework<django.contrib.sitemaps>` now makes use of
  114. :attr:`~django.contrib.sitemaps.Sitemap.lastmod` to set a ``Last-Modified``
  115. header in the response. This makes it possible for the
  116. :class:`~django.middleware.http.ConditionalGetMiddleware` to handle
  117. conditional ``GET`` requests for sitemaps which set ``lastmod``.
  118. * You can override the new :meth:`AuthenticationForm.confirm_login_allowed()
  119. <django.contrib.auth.forms.AuthenticationForm.confirm_login_allowed>` method
  120. to more easily customize the login policy.
  121. * :attr:`Field.choices<django.db.models.Field.choices>` now allows you to
  122. customize the "empty choice" label by including a tuple with an empty string
  123. or ``None`` for the key and the custom label as the value. The default blank
  124. option ``"----------"`` will be omitted in this case.
  125. * The admin's search fields can now be customized per-request thanks to the new
  126. :meth:`django.contrib.admin.ModelAdmin.get_search_fields` method.
  127. * The :meth:`ModelAdmin.get_fields()
  128. <django.contrib.admin.ModelAdmin.get_fields>` method may be overridden to
  129. customize the value of :attr:`ModelAdmin.fields
  130. <django.contrib.admin.ModelAdmin.fields>`.
  131. * :func:`django.contrib.auth.views.password_reset` takes an optional
  132. ``html_email_template_name`` parameter used to send a multipart HTML email
  133. for password resets.
  134. * :class:`~django.forms.MultiValueField` allows optional subfields by setting
  135. the ``require_all_fields`` argument to ``False``. The ``required`` attribute
  136. for each individual field will be respected, and a new ``incomplete``
  137. validation error will be raised when any required fields are empty.
  138. * The :meth:`~django.forms.Form.clean` method on a form no longer needs to
  139. return ``self.cleaned_data``. If it does return a changed dictionary then
  140. that will still be used.
  141. * The new :attr:`~django.db.models.Options.default_permissions` model
  142. ``Meta`` option allows you to customize (or disable) creation of the default
  143. add, change, and delete permissions.
  144. Backwards incompatible changes in 1.7
  145. =====================================
  146. .. warning::
  147. In addition to the changes outlined in this section, be sure to review the
  148. :doc:`deprecation plan </internals/deprecation>` for any features that
  149. have been removed. If you haven't updated your code within the
  150. deprecation timeline for a given feature, its removal may appear as a
  151. backwards incompatible change.
  152. allow_syncdb/allow_migrate
  153. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. While Django will still look at ``allow_syncdb`` methods even though they
  155. should be renamed to ``allow_migrate``, there is a subtle difference in which
  156. models get passed to these methods.
  157. For apps with migrations, ``allow_migrate`` will now get passed
  158. :ref:`historical models <historical-models>`, which are special versioned models
  159. without custom attributes, methods or managers. Make sure your ``allow_migrate``
  160. methods are only referring to fields or other items in ``model._meta``.
  161. Miscellaneous
  162. ~~~~~~~~~~~~~
  163. * The :meth:`django.core.files.uploadhandler.FileUploadHandler.new_file()`
  164. method is now passed an additional ``content_type_extra`` parameter. If you
  165. have a custom :class:`~django.core.files.uploadhandler.FileUploadHandler`
  166. that implements ``new_file()``, be sure it accepts this new parameter.
  167. * :class:`ModelFormSet<django.forms.models.BaseModelFormSet>`’s no longer
  168. delete instances when ``save(commit=False)`` is called. See
  169. :attr:`~django.forms.formsets.BaseFormSet.can_delete` for instructions on how
  170. to manually delete objects from deleted forms.
  171. * Loading empty fixtures emits a ``RuntimeWarning`` rather than raising
  172. :class:`~django.core.management.CommandError`.
  173. * :func:`django.contrib.staticfiles.views.serve` will now raise an
  174. :exc:`~django.http.Http404` exception instead of
  175. :exc:`~django.core.exceptions.ImproperlyConfigured` when :setting:`DEBUG`
  176. is ``False``. This change removes the need to conditionally add the view to
  177. your root URLconf, which in turn makes it safe to reverse by name. It also
  178. removes the ability for visitors to generate spurious HTTP 500 errors by
  179. requesting static files that don't exist or haven't been collected yet.
  180. Features deprecated in 1.7
  181. ==========================
  182. ``django.utils.dictconfig``/``django.utils.importlib``
  183. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  184. ``django.utils.dictconfig`` and ``django.utils.importlib`` were copies of
  185. respectively :mod:`logging.config` and :mod:`importlib` provided for Python
  186. versions prior to 2.7. They have been deprecated.
  187. ``django.utils.unittest``
  188. ~~~~~~~~~~~~~~~~~~~~~~~~~
  189. ``django.utils.unittest`` provided uniform access to the ``unittest2`` library
  190. on all Python versions. Since ``unittest2`` became the standard library's
  191. :mod:`unittest` module in Python 2.7, and Django 1.7 drops support for older
  192. Python versions, this module isn't useful anymore. It has been deprecated. Use
  193. :mod:`unittest` instead.
  194. ``django.utils.datastructures.SortedDict``
  195. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  196. As :class:`~collections.OrderedDict` was added to the standard library in
  197. Python 2.7, :class:`~django.utils.datastructures.SortedDict` is no longer
  198. needed and has been deprecated.
  199. Custom SQL location for models package
  200. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  201. Previously, if models were organized in a package (``myapp/models/``) rather
  202. than simply ``myapp/models.py``, Django would look for :ref:`initial SQL data
  203. <initial-sql>` in ``myapp/models/sql/``. This bug has been fixed so that Django
  204. will search ``myapp/sql/`` as documented. The old location will continue to
  205. work until Django 1.9.
  206. ``declared_fieldsets`` attribute on ``ModelAdmin.``
  207. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  208. ``ModelAdmin.declared_fieldsets`` was deprecated. Despite being a private API,
  209. it will go through a regular deprecation path. This attribute was mostly used
  210. by methods that bypassed ``ModelAdmin.get_fieldsets()`` but this was considered
  211. a bug and has been addressed.