1.1.txt 18 KB

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