1.1.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. ========================
  2. Django 1.1 release notes
  3. ========================
  4. July 29, 2009
  5. Welcome to Django 1.1!
  6. Django 1.1 includes a number of nifty `new features`_, lots of bug
  7. fixes, and an easy upgrade path from Django 1.0.
  8. .. _new features: `What's new in Django 1.1`_
  9. .. _backwards-incompatible-changes-1.1:
  10. Backwards-incompatible changes in 1.1
  11. =====================================
  12. Django has a policy of :doc:`API stability </misc/api-stability>`. This means
  13. that, in general, code you develop against Django 1.0 should continue to work
  14. against 1.1 unchanged. However, we do sometimes make backwards-incompatible
  15. changes if they're necessary to resolve bugs, and there are a handful of such
  16. (minor) changes between Django 1.0 and Django 1.1.
  17. Before upgrading to Django 1.1 you should double-check that the following
  18. changes don't impact you, and upgrade your code if they do.
  19. Changes to constraint names
  20. ---------------------------
  21. Django 1.1 modifies the method used to generate database constraint names so
  22. that names are consistent regardless of machine word size. This change is
  23. backwards incompatible for some users.
  24. If you are using a 32-bit platform, you're off the hook; you'll observe no
  25. differences as a result of this change.
  26. However, **users on 64-bit platforms may experience some problems** using the
  27. ``reset`` management command. Prior to this change, 64-bit platforms
  28. would generate a 64-bit, 16 character digest in the constraint name; for
  29. example::
  30. ALTER TABLE myapp_sometable ADD CONSTRAINT object_id_refs_id_5e8f10c132091d1e FOREIGN KEY ...
  31. Following this change, all platforms, regardless of word size, will generate a
  32. 32-bit, 8 character digest in the constraint name; for example::
  33. ALTER TABLE myapp_sometable ADD CONSTRAINT object_id_refs_id_32091d1e FOREIGN KEY ...
  34. As a result of this change, you will not be able to use the ``reset``
  35. management command on any table made by a 64-bit machine. This is because the
  36. the new generated name will not match the historically generated name; as a
  37. result, the SQL constructed by the reset command will be invalid.
  38. If you need to reset an application that was created with 64-bit constraints,
  39. you will need to manually drop the old constraint prior to invoking
  40. ``reset``.
  41. Test cases are now run in a transaction
  42. ---------------------------------------
  43. Django 1.1 runs tests inside a transaction, allowing better test performance
  44. (see `test performance improvements`_ for details).
  45. This change is slightly backwards incompatible if existing tests need to test
  46. transactional behavior, if they rely on invalid assumptions about the test
  47. environment, or if they require a specific test case ordering.
  48. For these cases, :class:`~django.test.TransactionTestCase` can be used instead.
  49. This is a just a quick fix to get around test case errors revealed by the new
  50. rollback approach; in the long-term tests should be rewritten to correct the
  51. test case.
  52. .. _removed-setremoteaddrfromforwardedfor-middleware:
  53. Removed ``SetRemoteAddrFromForwardedFor`` middleware
  54. ----------------------------------------------------
  55. For convenience, Django 1.0 included an optional middleware class --
  56. ``django.middleware.http.SetRemoteAddrFromForwardedFor`` -- which updated the
  57. value of ``REMOTE_ADDR`` based on the HTTP ``X-Forwarded-For`` header commonly
  58. set by some proxy configurations.
  59. It has been demonstrated that this mechanism cannot be made reliable enough for
  60. general-purpose use, and that (despite documentation to the contrary) its
  61. inclusion in Django may lead application developers to assume that the value of
  62. ``REMOTE_ADDR`` is "safe" or in some way reliable as a source of authentication.
  63. While not directly a security issue, we've decided to remove this middleware
  64. with the Django 1.1 release. It has been replaced with a class that does nothing
  65. other than raise a ``DeprecationWarning``.
  66. If you've been relying on this middleware, the easiest upgrade path is:
  67. * Examine `the code as it existed before it was removed`__.
  68. * Verify that it works correctly with your upstream proxy, modifying
  69. it to support your particular proxy (if necessary).
  70. * Introduce your modified version of ``SetRemoteAddrFromForwardedFor`` as a
  71. piece of middleware in your own project.
  72. __ https://github.com/django/django/blob/91f18400cc0fb37659e2dbaab5484ff2081f1f30/django/middleware/http.py#L33
  73. Names of uploaded files are available later
  74. -------------------------------------------
  75. .. currentmodule:: django.db.models
  76. In Django 1.0, files uploaded and stored in a model's :class:`FileField` were
  77. saved to disk before the model was saved to the database. This meant that the
  78. actual file name assigned to the file was available before saving. For example,
  79. it was available in a model's pre-save signal handler.
  80. In Django 1.1 the file is saved as part of saving the model in the database, so
  81. the actual file name used on disk cannot be relied on until *after* the model
  82. has been saved.
  83. Changes to how model formsets are saved
  84. ---------------------------------------
  85. In Django 1.1, :class:`~django.forms.models.BaseModelFormSet` now calls
  86. ``ModelForm.save()``.
  87. This is backwards-incompatible if you were modifying ``self.initial`` in a model
  88. formset's ``__init__``, or if you relied on the internal ``_total_form_count``
  89. or ``_initial_form_count`` attributes of BaseFormSet. Those attributes are now
  90. public methods.
  91. Fixed the ``join`` filter's escaping behavior
  92. ---------------------------------------------
  93. The :tfilter:`join` filter no longer escapes the literal value that is
  94. passed in for the connector.
  95. This is backwards incompatible for the special situation of the literal string
  96. containing one of the five special HTML characters. Thus, if you were writing
  97. ``{{ foo|join:"&" }}``, you now have to write ``{{ foo|join:"&amp;" }}``.
  98. The previous behavior was a bug and contrary to what was documented
  99. and expected.
  100. Permanent redirects and the ``redirect_to()`` generic view
  101. ----------------------------------------------------------
  102. Django 1.1 adds a ``permanent`` argument to the
  103. ``django.views.generic.simple.redirect_to()`` view. This is technically
  104. backwards-incompatible if you were using the ``redirect_to`` view with a
  105. format-string key called 'permanent', which is highly unlikely.
  106. .. _deprecated-features-1.1:
  107. Features deprecated in 1.1
  108. ==========================
  109. One feature has been marked as deprecated in Django 1.1:
  110. * You should no longer use ``AdminSite.root()`` to register that admin
  111. views. That is, if your URLconf contains the line::
  112. (r'^admin/(.*)', admin.site.root),
  113. You should change it to read::
  114. (r'^admin/', include(admin.site.urls)),
  115. You should begin to remove use of this feature from your code immediately.
  116. ``AdminSite.root`` will raise a ``PendingDeprecationWarning`` if used in
  117. Django 1.1. This warning is hidden by default. In Django 1.2, this warning will
  118. be upgraded to a ``DeprecationWarning``, which will be displayed loudly. Django
  119. 1.3 will remove ``AdminSite.root()`` entirely.
  120. For more details on our deprecation policies and strategy, see
  121. :doc:`/internals/release-process`.
  122. What's new in Django 1.1
  123. ========================
  124. Quite a bit: since Django 1.0, we've made 1,290 code commits, fixed 1,206 bugs,
  125. and added roughly 10,000 lines of documentation.
  126. The major new features in Django 1.1 are:
  127. ORM improvements
  128. ----------------
  129. .. currentmodule:: django.db.models
  130. Two major enhancements have been added to Django's object-relational mapper
  131. (ORM): aggregate support, and query expressions.
  132. Aggregate support
  133. ~~~~~~~~~~~~~~~~~
  134. It's now possible to run SQL aggregate queries (i.e. ``COUNT()``, ``MAX()``,
  135. ``MIN()``, etc.) from within Django's ORM. You can choose to either return the
  136. results of the aggregate directly, or else annotate the objects in a
  137. :class:`~django.db.models.query.QuerySet` with the results of the aggregate
  138. query.
  139. This feature is available as new
  140. :meth:`~django.db.models.query.QuerySet.aggregate` and
  141. :meth:`~django.db.models.query.QuerySet.annotate` methods, and is covered in
  142. detail in :doc:`the ORM aggregation documentation </topics/db/aggregation>`.
  143. Query expressions
  144. ~~~~~~~~~~~~~~~~~
  145. Queries can now refer to a another field on the query and can traverse
  146. relationships to refer to fields on related models. This is implemented in the
  147. new :class:`~django.db.models.F` object; for full details, including examples,
  148. consult the :class:`F expressions documentation <django.db.models.F>`.
  149. Model improvements
  150. ------------------
  151. A number of features have been added to Django's model layer:
  152. "Unmanaged" models
  153. ~~~~~~~~~~~~~~~~~~
  154. You can now control whether or not Django manages the life-cycle of the database
  155. tables for a model using the :attr:`~Options.managed` model option. This
  156. defaults to ``True``, meaning that Django will create the appropriate database
  157. tables in :djadmin:`syncdb` and remove them as part of the ``reset``
  158. command. That is, Django *manages* the database table's lifecycle.
  159. If you set this to ``False``, however, no database table creating or deletion
  160. will be automatically performed for this model. This is useful if the model
  161. represents an existing table or a database view that has been created by some
  162. other means.
  163. For more details, see the documentation for the :attr:`~Options.managed`
  164. option.
  165. Proxy models
  166. ~~~~~~~~~~~~
  167. You can now create :ref:`proxy models <proxy-models>`: subclasses of existing
  168. models that only add Python-level (rather than database-level) behavior and
  169. aren't represented by a new table. That is, the new model is a *proxy* for some
  170. underlying model, which stores all the real data.
  171. All the details can be found in the :ref:`proxy models documentation
  172. <proxy-models>`. This feature is similar on the surface to unmanaged models,
  173. so the documentation has an explanation of :ref:`how proxy models differ from
  174. unmanaged models <proxy-vs-unmanaged-models>`.
  175. Deferred fields
  176. ~~~~~~~~~~~~~~~
  177. In some complex situations, your models might contain fields which could
  178. contain a lot of data (for example, large text fields), or require expensive
  179. processing to convert them to Python objects. If you know you don't need those
  180. particular fields, you can now tell Django not to retrieve them from the
  181. database.
  182. You'll do this with the new queryset methods
  183. :meth:`~django.db.models.query.QuerySet.defer` and
  184. :meth:`~django.db.models.query.QuerySet.only`.
  185. Testing improvements
  186. --------------------
  187. A few notable improvements have been made to the :doc:`testing framework
  188. </topics/testing/index>`.
  189. Test performance improvements
  190. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  191. .. currentmodule:: django.test
  192. Tests written using Django's :doc:`testing framework </topics/testing/index>` now run
  193. dramatically faster (as much as 10 times faster in many cases).
  194. This was accomplished through the introduction of transaction-based tests: when
  195. using :class:`django.test.TestCase`, your tests will now be run in a transaction
  196. which is rolled back when finished, instead of by flushing and re-populating the
  197. database. This results in an immense speedup for most types of unit tests. See
  198. the documentation for :class:`TestCase` and :class:`TransactionTestCase` for a
  199. full description, and some important notes on database support.
  200. Test client improvements
  201. ------------------------
  202. .. currentmodule:: django.test.client
  203. A couple of small -- but highly useful -- improvements have been made to the
  204. test client:
  205. * The test :class:`Client` now can automatically follow redirects with the
  206. ``follow`` argument to :meth:`Client.get` and :meth:`Client.post`. This
  207. makes testing views that issue redirects simpler.
  208. * It's now easier to get at the template context in the response returned
  209. the test client: you'll simply access the context as
  210. ``request.context[key]``. The old way, which treats ``request.context`` as
  211. a list of contexts, one for each rendered template in the inheritance
  212. chain, is still available if you need it.
  213. New admin features
  214. ------------------
  215. Django 1.1 adds a couple of nifty new features to Django's admin interface:
  216. Editable fields on the change list
  217. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. You can now make fields editable on the admin list views via the new
  219. :ref:`list_editable <admin-list-editable>` admin option. These fields will show
  220. up as form widgets on the list pages, and can be edited and saved in bulk.
  221. Admin "actions"
  222. ~~~~~~~~~~~~~~~
  223. You can now define :doc:`admin actions </ref/contrib/admin/actions>` that can
  224. perform some action to a group of models in bulk. Users will be able to select
  225. objects on the change list page and then apply these bulk actions to all
  226. selected objects.
  227. Django ships with one pre-defined admin action to delete a group of objects in
  228. one fell swoop.
  229. Conditional view processing
  230. ---------------------------
  231. Django now has much better support for :doc:`conditional view processing
  232. </topics/conditional-view-processing>` using the standard ``ETag`` and
  233. ``Last-Modified`` HTTP headers. This means you can now easily short-circuit
  234. view processing by testing less-expensive conditions. For many views this can
  235. lead to a serious improvement in speed and reduction in bandwidth.
  236. URL namespaces
  237. --------------
  238. Django 1.1 improves :ref:`named URL patterns <naming-url-patterns>` with the
  239. introduction of URL "namespaces."
  240. In short, this feature allows the same group of URLs, from the same application,
  241. to be included in a Django URLConf multiple times, with varying (and potentially
  242. nested) named prefixes which will be used when performing reverse resolution. In
  243. other words, reusable applications like Django's admin interface may be
  244. registered multiple times without URL conflicts.
  245. For full details, see :ref:`the documentation on defining URL namespaces
  246. <topics-http-defining-url-namespaces>`.
  247. GeoDjango
  248. ---------
  249. In Django 1.1, GeoDjango_ (i.e. ``django.contrib.gis``) has several new
  250. features:
  251. * Support for SpatiaLite_ -- a spatial database for SQLite -- as a spatial
  252. backend.
  253. * Geographic aggregates (``Collect``, ``Extent``, ``MakeLine``, ``Union``)
  254. and ``F`` expressions.
  255. * New ``GeoQuerySet`` methods: ``collect``, ``geojson``, and
  256. ``snap_to_grid``.
  257. * A new list interface methods for ``GEOSGeometry`` objects.
  258. For more details, see the `GeoDjango documentation`_.
  259. .. _geodjango: http://geodjango.org/
  260. .. _spatialite: http://www.gaia-gis.it/gaia-sins/
  261. .. _geodjango documentation: http://geodjango.org/docs/
  262. Other improvements
  263. ------------------
  264. Other new features and changes introduced since Django 1.0 include:
  265. * The :doc:`CSRF protection middleware </ref/contrib/csrf>` has been split into
  266. two classes -- ``CsrfViewMiddleware`` checks incoming requests, and
  267. ``CsrfResponseMiddleware`` processes outgoing responses. The combined
  268. ``CsrfMiddleware`` class (which does both) remains for
  269. backwards-compatibility, but using the split classes is now recommended in
  270. order to allow fine-grained control of when and where the CSRF processing
  271. takes place.
  272. * :func:`~django.core.urlresolvers.reverse` and code which uses it (e.g., the
  273. ``{% url %}`` template tag) now works with URLs in Django's administrative
  274. site, provided that the admin URLs are set up via ``include(admin.site.urls)``
  275. (sending admin requests to the ``admin.site.root`` view still works, but URLs
  276. in the admin will not be "reversible" when configured this way).
  277. * The ``include()`` function in Django URLconf modules can now accept sequences
  278. of URL patterns (generated by ``patterns()``) in addition to module names.
  279. * Instances of Django forms (see :doc:`the forms overview </topics/forms/index>`)
  280. now have two additional methods, ``hidden_fields()`` and ``visible_fields()``,
  281. which return the list of hidden -- i.e., ``<input type="hidden">`` -- and
  282. visible fields on the form, respectively.
  283. * The ``redirect_to`` generic view
  284. now accepts an additional keyword argument
  285. ``permanent``. If ``permanent`` is ``True``, the view will emit an HTTP
  286. permanent redirect (status code 301). If ``False``, the view will emit an HTTP
  287. temporary redirect (status code 302).
  288. * A new database lookup type -- ``week_day`` -- has been added for ``DateField``
  289. and ``DateTimeField``. This type of lookup accepts a number between 1 (Sunday)
  290. and 7 (Saturday), and returns objects where the field value matches that day
  291. of the week. See :ref:`the full list of lookup types <field-lookups>` for
  292. details.
  293. * The ``{% for %}`` tag in Django's template language now accepts an optional
  294. ``{% empty %}`` clause, to be displayed when ``{% for %}`` is asked to loop
  295. over an empty sequence. See :doc:`the list of built-in template tags
  296. </ref/templates/builtins>` for examples of this.
  297. * The :djadmin:`dumpdata` management command now accepts individual
  298. model names as arguments, allowing you to export the data just from
  299. particular models.
  300. * There's a new :tfilter:`safeseq` template filter which works just like
  301. :tfilter:`safe` for lists, marking each item in the list as safe.
  302. * :doc:`Cache backends </topics/cache>` now support ``incr()`` and
  303. ``decr()`` commands to increment and decrement the value of a cache key.
  304. On cache backends that support atomic increment/decrement -- most
  305. notably, the memcached backend -- these operations will be atomic, and
  306. quite fast.
  307. * Django now can :doc:`easily delegate authentication to the Web server
  308. </howto/auth-remote-user>` via a new authentication backend that supports
  309. the standard ``REMOTE_USER`` environment variable used for this purpose.
  310. * There's a new :func:`django.shortcuts.redirect` function that makes it
  311. easier to issue redirects given an object, a view name, or a URL.
  312. * The ``postgresql_psycopg2`` backend now supports :ref:`native PostgreSQL
  313. autocommit <postgresql-notes>`. This is an advanced, PostgreSQL-specific
  314. feature, that can make certain read-heavy applications a good deal
  315. faster.
  316. What's next?
  317. ============
  318. We'll take a short break, and then work on Django 1.2 will begin -- no rest for
  319. the weary! If you'd like to help, discussion of Django development, including
  320. progress toward the 1.2 release, takes place daily on the django-developers
  321. mailing list:
  322. * http://groups.google.com/group/django-developers
  323. ... and in the ``#django-dev`` IRC channel on ``irc.freenode.net``. Feel free to
  324. join the discussions!
  325. Django's online documentation also includes pointers on how to contribute to
  326. Django:
  327. * :doc:`How to contribute to Django </internals/contributing/index>`
  328. Contributions on any level -- developing code, writing documentation or simply
  329. triaging tickets and helping to test proposed bugfixes -- are always welcome and
  330. appreciated.
  331. And that's the way it is.